<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><link rel="stylesheet" type="text/css" href="style.css" /><script type="text/javascript" src="highlight.js"></script></head><body><pre><span class="hs-pragma">{-# LANGUAGE Trustworthy #-}</span><span>
</span><span id="line-2"></span><span class="hs-pragma">{-# LANGUAGE CPP, NoImplicitPrelude, MagicHash, UnboxedTuples #-}</span><span>
</span><span id="line-3"></span><span class="hs-pragma">{-# OPTIONS_GHC -Wno-missing-signatures #-}</span><span>
</span><span id="line-4"></span><span class="hs-pragma">{-# OPTIONS_HADDOCK not-home #-}</span><span>
</span><span id="line-5"></span><span>
</span><span id="line-6"></span><span class="hs-comment">-----------------------------------------------------------------------------</span><span>
</span><span id="line-7"></span><span class="hs-comment">-- |</span><span>
</span><span id="line-8"></span><span class="hs-comment">-- Module      :  GHC.Conc.POSIX</span><span>
</span><span id="line-9"></span><span class="hs-comment">-- Copyright   :  (c) The University of Glasgow, 1994-2002</span><span>
</span><span id="line-10"></span><span class="hs-comment">-- License     :  see libraries/base/LICENSE</span><span>
</span><span id="line-11"></span><span class="hs-comment">--</span><span>
</span><span id="line-12"></span><span class="hs-comment">-- Maintainer  :  cvs-ghc@haskell.org</span><span>
</span><span id="line-13"></span><span class="hs-comment">-- Stability   :  internal</span><span>
</span><span id="line-14"></span><span class="hs-comment">-- Portability :  non-portable (GHC extensions)</span><span>
</span><span id="line-15"></span><span class="hs-comment">--</span><span>
</span><span id="line-16"></span><span class="hs-comment">-- Windows I/O manager</span><span>
</span><span id="line-17"></span><span class="hs-comment">--</span><span>
</span><span id="line-18"></span><span class="hs-comment">-- This is the I/O manager based on posix FDs for windows.</span><span>
</span><span id="line-19"></span><span class="hs-comment">-- When using the winio manager these functions may not</span><span>
</span><span id="line-20"></span><span class="hs-comment">-- be used as they will behave in unexpected ways.</span><span>
</span><span id="line-21"></span><span class="hs-comment">--</span><span>
</span><span id="line-22"></span><span class="hs-comment">-- TODO: This manager is currently the default. But we will eventually</span><span>
</span><span id="line-23"></span><span class="hs-comment">-- switch to use winio instead.</span><span>
</span><span id="line-24"></span><span class="hs-comment">--</span><span>
</span><span id="line-25"></span><span class="hs-comment">-----------------------------------------------------------------------------</span><span>
</span><span id="line-26"></span><span>
</span><span id="line-27"></span><span class="hs-comment">-- #not-home</span><span>
</span><span id="line-28"></span><span class="hs-keyword">module</span><span> </span><span class="hs-identifier">GHC.Conc.POSIX</span><span>
</span><span id="line-29"></span><span>       </span><span class="hs-special">(</span><span> </span><span class="annot"><a href="GHC.Conc.POSIX.html#ensureIOManagerIsRunning"><span class="hs-identifier">ensureIOManagerIsRunning</span></a></span><span>
</span><span id="line-30"></span><span>       </span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Conc.POSIX.html#interruptIOManager"><span class="hs-identifier">interruptIOManager</span></a></span><span>
</span><span id="line-31"></span><span>
</span><span id="line-32"></span><span>       </span><span class="annot"><span class="hs-comment">-- * Waiting</span></span><span>
</span><span id="line-33"></span><span>       </span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Conc.POSIX.html#threadDelay"><span class="hs-identifier">threadDelay</span></a></span><span>
</span><span id="line-34"></span><span>       </span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Conc.POSIX.html#registerDelay"><span class="hs-identifier">registerDelay</span></a></span><span>
</span><span id="line-35"></span><span>
</span><span id="line-36"></span><span>       </span><span class="annot"><span class="hs-comment">-- * Miscellaneous</span></span><span>
</span><span id="line-37"></span><span>       </span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Conc.POSIX.html#asyncRead"><span class="hs-identifier">asyncRead</span></a></span><span>
</span><span id="line-38"></span><span>       </span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Conc.POSIX.html#asyncWrite"><span class="hs-identifier">asyncWrite</span></a></span><span>
</span><span id="line-39"></span><span>       </span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Conc.POSIX.html#asyncDoProc"><span class="hs-identifier">asyncDoProc</span></a></span><span>
</span><span id="line-40"></span><span>
</span><span id="line-41"></span><span>       </span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Conc.POSIX.html#asyncReadBA"><span class="hs-identifier">asyncReadBA</span></a></span><span>
</span><span id="line-42"></span><span>       </span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Conc.POSIX.html#asyncWriteBA"><span class="hs-identifier">asyncWriteBA</span></a></span><span>
</span><span id="line-43"></span><span>
</span><span id="line-44"></span><span>       </span><span class="hs-special">,</span><span> </span><span class="hs-keyword">module</span><span> </span><span class="annot"><a href="GHC.Event.Windows.ConsoleEvent.html"><span class="hs-identifier">GHC.Event.Windows.ConsoleEvent</span></a></span><span>
</span><span id="line-45"></span><span>       </span><span class="hs-special">)</span><span> </span><span class="hs-keyword">where</span><span class="hs-cpp">


#include &quot;windows_cconv.h&quot;
</span><span>
</span><span id="line-50"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="Data.Bits.html"><span class="hs-identifier">Data.Bits</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="Data.Bits.html#shiftR"><span class="hs-identifier">shiftR</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-51"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Base.html"><span class="hs-identifier">GHC.Base</span></a></span><span>
</span><span id="line-52"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Conc.Sync.html"><span class="hs-identifier">GHC.Conc.Sync</span></a></span><span>
</span><span id="line-53"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Conc.POSIX.Const.html"><span class="hs-identifier">GHC.Conc.POSIX.Const</span></a></span><span>
</span><span id="line-54"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Event.Windows.ConsoleEvent.html"><span class="hs-identifier">GHC.Event.Windows.ConsoleEvent</span></a></span><span>
</span><span id="line-55"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.IO.html"><span class="hs-identifier">GHC.IO</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.IO.Unsafe.html#unsafePerformIO"><span class="hs-identifier">unsafePerformIO</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-56"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.IORef.html"><span class="hs-identifier">GHC.IORef</span></a></span><span>
</span><span id="line-57"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.MVar.html"><span class="hs-identifier">GHC.MVar</span></a></span><span>
</span><span id="line-58"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Num.html"><span class="hs-identifier">GHC.Num</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Num.html#Num"><span class="hs-identifier">Num</span></a></span><span class="hs-special">(</span><span class="hs-glyph">..</span><span class="hs-special">)</span><span class="hs-special">)</span><span>
</span><span id="line-59"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Ptr.html"><span class="hs-identifier">GHC.Ptr</span></a></span><span>
</span><span id="line-60"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Real.html"><span class="hs-identifier">GHC.Real</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Real.html#div"><span class="hs-identifier">div</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Real.html#fromIntegral"><span class="hs-identifier">fromIntegral</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-61"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Word.html"><span class="hs-identifier">GHC.Word</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Word.html#Word32"><span class="hs-identifier">Word32</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Word.html#Word64"><span class="hs-identifier">Word64</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-62"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Windows.html"><span class="hs-identifier">GHC.Windows</span></a></span><span>
</span><span id="line-63"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="Unsafe.Coerce.html"><span class="hs-identifier">Unsafe.Coerce</span></a></span><span> </span><span class="hs-special">(</span><span> </span><span class="annot"><a href="Unsafe.Coerce.html#unsafeCoerceUnlifted"><span class="hs-identifier">unsafeCoerceUnlifted</span></a></span><span> </span><span class="hs-special">)</span><span>
</span><span id="line-64"></span><span>
</span><span id="line-65"></span><span class="hs-comment">-- ----------------------------------------------------------------------------</span><span>
</span><span id="line-66"></span><span class="hs-comment">-- Thread waiting</span><span>
</span><span id="line-67"></span><span>
</span><span id="line-68"></span><span class="hs-comment">-- Note: threadWaitRead and threadWaitWrite aren't really functional</span><span>
</span><span id="line-69"></span><span class="hs-comment">-- on Win32, but left in there because lib code (still) uses them (the manner</span><span>
</span><span id="line-70"></span><span class="hs-comment">-- in which they're used doesn't cause problems on a Win32 platform though.)</span><span>
</span><span id="line-71"></span><span>
</span><span id="line-72"></span><span id="local-6989586621679554186"><span class="annot"><a href="GHC.Conc.POSIX.html#asyncRead"><span class="hs-identifier hs-type">asyncRead</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#Int"><span class="hs-identifier hs-type">Int</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#Int"><span class="hs-identifier hs-type">Int</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#Int"><span class="hs-identifier hs-type">Int</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Ptr.html#Ptr"><span class="hs-identifier hs-type">Ptr</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679554186"><span class="hs-identifier hs-type">a</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#Int"><span class="hs-identifier hs-type">Int</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#Int"><span class="hs-identifier hs-type">Int</span></a></span><span class="hs-special">)</span></span><span>
</span><span id="line-73"></span><span id="asyncRead"><span class="annot"><span class="annottext">asyncRead :: forall a. Int -&gt; Int -&gt; Int -&gt; Ptr a -&gt; IO (Int, Int)
</span><a href="GHC.Conc.POSIX.html#asyncRead"><span class="hs-identifier hs-var hs-var">asyncRead</span></a></span></span><span>  </span><span class="hs-special">(</span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#I%23"><span class="hs-identifier hs-type">I#</span></a></span><span> </span><span id="local-6989586621679554049"><span class="annot"><span class="annottext">Int#
</span><a href="#local-6989586621679554049"><span class="hs-identifier hs-var">fd</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-special">(</span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#I%23"><span class="hs-identifier hs-type">I#</span></a></span><span> </span><span id="local-6989586621679554048"><span class="annot"><span class="annottext">Int#
</span><a href="#local-6989586621679554048"><span class="hs-identifier hs-var">isSock</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-special">(</span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#I%23"><span class="hs-identifier hs-type">I#</span></a></span><span> </span><span id="local-6989586621679554047"><span class="annot"><span class="annottext">Int#
</span><a href="#local-6989586621679554047"><span class="hs-identifier hs-var">len</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Ptr.html#Ptr"><span class="hs-identifier hs-type">Ptr</span></a></span><span> </span><span id="local-6989586621679554045"><span class="annot"><span class="annottext">Addr#
</span><a href="#local-6989586621679554045"><span class="hs-identifier hs-var">buf</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span>
</span><span id="line-74"></span><span>  </span><span class="annot"><span class="annottext">(State# RealWorld -&gt; (# State# RealWorld, (Int, Int) #))
-&gt; IO (Int, Int)
forall a. (State# RealWorld -&gt; (# State# RealWorld, a #)) -&gt; IO a
</span><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-var">IO</span></a></span><span> </span><span class="annot"><span class="annottext">((State# RealWorld -&gt; (# State# RealWorld, (Int, Int) #))
 -&gt; IO (Int, Int))
-&gt; (State# RealWorld -&gt; (# State# RealWorld, (Int, Int) #))
-&gt; IO (Int, Int)
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="hs-glyph">\</span><span id="local-6989586621679554044"><span class="annot"><span class="annottext">State# RealWorld
</span><a href="#local-6989586621679554044"><span class="hs-identifier hs-var">s</span></a></span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-keyword">case</span><span> </span><span class="annot"><span class="annottext">Int#
-&gt; Int#
-&gt; Int#
-&gt; Addr#
-&gt; State# RealWorld
-&gt; (# State# RealWorld, Int#, Int# #)
</span><a href="../../ghc-prim/src/GHC.Prim.Ext.html#asyncRead%23"><span class="hs-identifier hs-var">asyncRead#</span></a></span><span> </span><span class="annot"><span class="annottext">Int#
</span><a href="#local-6989586621679554049"><span class="hs-identifier hs-var">fd</span></a></span><span> </span><span class="annot"><span class="annottext">Int#
</span><a href="#local-6989586621679554048"><span class="hs-identifier hs-var">isSock</span></a></span><span> </span><span class="annot"><span class="annottext">Int#
</span><a href="#local-6989586621679554047"><span class="hs-identifier hs-var">len</span></a></span><span> </span><span class="annot"><span class="annottext">Addr#
</span><a href="#local-6989586621679554045"><span class="hs-identifier hs-var">buf</span></a></span><span> </span><span class="annot"><span class="annottext">State# RealWorld
</span><a href="#local-6989586621679554044"><span class="hs-identifier hs-var">s</span></a></span><span> </span><span class="hs-keyword">of</span><span>
</span><span id="line-75"></span><span>               </span><span class="hs-special">(#</span><span> </span><span id="local-6989586621679554042"><span class="annot"><span class="annottext">State# RealWorld
</span><a href="#local-6989586621679554042"><span class="hs-identifier hs-var">s'</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621679554041"><span class="annot"><span class="annottext">Int#
</span><a href="#local-6989586621679554041"><span class="hs-identifier hs-var">len#</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621679554040"><span class="annot"><span class="annottext">Int#
</span><a href="#local-6989586621679554040"><span class="hs-identifier hs-var">err#</span></a></span></span><span> </span><span class="hs-special">#)</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">(#</span><span> </span><span class="annot"><span class="annottext">State# RealWorld
</span><a href="#local-6989586621679554042"><span class="hs-identifier hs-var">s'</span></a></span><span class="hs-special">,</span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Int# -&gt; Int
</span><a href="../../ghc-prim/src/GHC.Types.html#I%23"><span class="hs-identifier hs-var">I#</span></a></span><span> </span><span class="annot"><span class="annottext">Int#
</span><a href="#local-6989586621679554041"><span class="hs-identifier hs-var">len#</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">Int# -&gt; Int
</span><a href="../../ghc-prim/src/GHC.Types.html#I%23"><span class="hs-identifier hs-var">I#</span></a></span><span> </span><span class="annot"><span class="annottext">Int#
</span><a href="#local-6989586621679554040"><span class="hs-identifier hs-var">err#</span></a></span><span class="hs-special">)</span><span> </span><span class="hs-special">#)</span><span>
</span><span id="line-76"></span><span>
</span><span id="line-77"></span><span id="local-6989586621679554039"><span class="annot"><a href="GHC.Conc.POSIX.html#asyncWrite"><span class="hs-identifier hs-type">asyncWrite</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#Int"><span class="hs-identifier hs-type">Int</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#Int"><span class="hs-identifier hs-type">Int</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#Int"><span class="hs-identifier hs-type">Int</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Ptr.html#Ptr"><span class="hs-identifier hs-type">Ptr</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679554039"><span class="hs-identifier hs-type">a</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#Int"><span class="hs-identifier hs-type">Int</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#Int"><span class="hs-identifier hs-type">Int</span></a></span><span class="hs-special">)</span></span><span>
</span><span id="line-78"></span><span id="asyncWrite"><span class="annot"><span class="annottext">asyncWrite :: forall a. Int -&gt; Int -&gt; Int -&gt; Ptr a -&gt; IO (Int, Int)
</span><a href="GHC.Conc.POSIX.html#asyncWrite"><span class="hs-identifier hs-var hs-var">asyncWrite</span></a></span></span><span>  </span><span class="hs-special">(</span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#I%23"><span class="hs-identifier hs-type">I#</span></a></span><span> </span><span id="local-6989586621679554038"><span class="annot"><span class="annottext">Int#
</span><a href="#local-6989586621679554038"><span class="hs-identifier hs-var">fd</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-special">(</span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#I%23"><span class="hs-identifier hs-type">I#</span></a></span><span> </span><span id="local-6989586621679554037"><span class="annot"><span class="annottext">Int#
</span><a href="#local-6989586621679554037"><span class="hs-identifier hs-var">isSock</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-special">(</span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#I%23"><span class="hs-identifier hs-type">I#</span></a></span><span> </span><span id="local-6989586621679554036"><span class="annot"><span class="annottext">Int#
</span><a href="#local-6989586621679554036"><span class="hs-identifier hs-var">len</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Ptr.html#Ptr"><span class="hs-identifier hs-type">Ptr</span></a></span><span> </span><span id="local-6989586621679554035"><span class="annot"><span class="annottext">Addr#
</span><a href="#local-6989586621679554035"><span class="hs-identifier hs-var">buf</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span>
</span><span id="line-79"></span><span>  </span><span class="annot"><span class="annottext">(State# RealWorld -&gt; (# State# RealWorld, (Int, Int) #))
-&gt; IO (Int, Int)
forall a. (State# RealWorld -&gt; (# State# RealWorld, a #)) -&gt; IO a
</span><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-var">IO</span></a></span><span> </span><span class="annot"><span class="annottext">((State# RealWorld -&gt; (# State# RealWorld, (Int, Int) #))
 -&gt; IO (Int, Int))
-&gt; (State# RealWorld -&gt; (# State# RealWorld, (Int, Int) #))
-&gt; IO (Int, Int)
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="hs-glyph">\</span><span id="local-6989586621679554034"><span class="annot"><span class="annottext">State# RealWorld
</span><a href="#local-6989586621679554034"><span class="hs-identifier hs-var">s</span></a></span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-keyword">case</span><span> </span><span class="annot"><span class="annottext">Int#
-&gt; Int#
-&gt; Int#
-&gt; Addr#
-&gt; State# RealWorld
-&gt; (# State# RealWorld, Int#, Int# #)
</span><a href="../../ghc-prim/src/GHC.Prim.Ext.html#asyncWrite%23"><span class="hs-identifier hs-var">asyncWrite#</span></a></span><span> </span><span class="annot"><span class="annottext">Int#
</span><a href="#local-6989586621679554038"><span class="hs-identifier hs-var">fd</span></a></span><span> </span><span class="annot"><span class="annottext">Int#
</span><a href="#local-6989586621679554037"><span class="hs-identifier hs-var">isSock</span></a></span><span> </span><span class="annot"><span class="annottext">Int#
</span><a href="#local-6989586621679554036"><span class="hs-identifier hs-var">len</span></a></span><span> </span><span class="annot"><span class="annottext">Addr#
</span><a href="#local-6989586621679554035"><span class="hs-identifier hs-var">buf</span></a></span><span> </span><span class="annot"><span class="annottext">State# RealWorld
</span><a href="#local-6989586621679554034"><span class="hs-identifier hs-var">s</span></a></span><span> </span><span class="hs-keyword">of</span><span>
</span><span id="line-80"></span><span>               </span><span class="hs-special">(#</span><span> </span><span id="local-6989586621679554032"><span class="annot"><span class="annottext">State# RealWorld
</span><a href="#local-6989586621679554032"><span class="hs-identifier hs-var">s'</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621679554031"><span class="annot"><span class="annottext">Int#
</span><a href="#local-6989586621679554031"><span class="hs-identifier hs-var">len#</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621679554030"><span class="annot"><span class="annottext">Int#
</span><a href="#local-6989586621679554030"><span class="hs-identifier hs-var">err#</span></a></span></span><span> </span><span class="hs-special">#)</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">(#</span><span> </span><span class="annot"><span class="annottext">State# RealWorld
</span><a href="#local-6989586621679554032"><span class="hs-identifier hs-var">s'</span></a></span><span class="hs-special">,</span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Int# -&gt; Int
</span><a href="../../ghc-prim/src/GHC.Types.html#I%23"><span class="hs-identifier hs-var">I#</span></a></span><span> </span><span class="annot"><span class="annottext">Int#
</span><a href="#local-6989586621679554031"><span class="hs-identifier hs-var">len#</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">Int# -&gt; Int
</span><a href="../../ghc-prim/src/GHC.Types.html#I%23"><span class="hs-identifier hs-var">I#</span></a></span><span> </span><span class="annot"><span class="annottext">Int#
</span><a href="#local-6989586621679554030"><span class="hs-identifier hs-var">err#</span></a></span><span class="hs-special">)</span><span> </span><span class="hs-special">#)</span><span>
</span><span id="line-81"></span><span>
</span><span id="line-82"></span><span id="local-6989586621679554179"><span class="annot"><a href="GHC.Conc.POSIX.html#asyncDoProc"><span class="hs-identifier hs-type">asyncDoProc</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Ptr.html#FunPtr"><span class="hs-identifier hs-type">FunPtr</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Ptr.html#Ptr"><span class="hs-identifier hs-type">Ptr</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679554179"><span class="hs-identifier hs-type">a</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#Int"><span class="hs-identifier hs-type">Int</span></a></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Ptr.html#Ptr"><span class="hs-identifier hs-type">Ptr</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679554179"><span class="hs-identifier hs-type">a</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#Int"><span class="hs-identifier hs-type">Int</span></a></span></span><span>
</span><span id="line-83"></span><span id="asyncDoProc"><span class="annot"><span class="annottext">asyncDoProc :: forall a. FunPtr (Ptr a -&gt; IO Int) -&gt; Ptr a -&gt; IO Int
</span><a href="GHC.Conc.POSIX.html#asyncDoProc"><span class="hs-identifier hs-var hs-var">asyncDoProc</span></a></span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Ptr.html#FunPtr"><span class="hs-identifier hs-type">FunPtr</span></a></span><span> </span><span id="local-6989586621679554028"><span class="annot"><span class="annottext">Addr#
</span><a href="#local-6989586621679554028"><span class="hs-identifier hs-var">proc</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Ptr.html#Ptr"><span class="hs-identifier hs-type">Ptr</span></a></span><span> </span><span id="local-6989586621679554027"><span class="annot"><span class="annottext">Addr#
</span><a href="#local-6989586621679554027"><span class="hs-identifier hs-var">param</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span>
</span><span id="line-84"></span><span>    </span><span class="hs-comment">-- the 'length' value is ignored; simplifies implementation of</span><span>
</span><span id="line-85"></span><span>    </span><span class="hs-comment">-- the async*# primops to have them all return the same result.</span><span>
</span><span id="line-86"></span><span>  </span><span class="annot"><span class="annottext">(State# RealWorld -&gt; (# State# RealWorld, Int #)) -&gt; IO Int
forall a. (State# RealWorld -&gt; (# State# RealWorld, a #)) -&gt; IO a
</span><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-var">IO</span></a></span><span> </span><span class="annot"><span class="annottext">((State# RealWorld -&gt; (# State# RealWorld, Int #)) -&gt; IO Int)
-&gt; (State# RealWorld -&gt; (# State# RealWorld, Int #)) -&gt; IO Int
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="hs-glyph">\</span><span id="local-6989586621679554026"><span class="annot"><span class="annottext">State# RealWorld
</span><a href="#local-6989586621679554026"><span class="hs-identifier hs-var">s</span></a></span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-keyword">case</span><span> </span><span class="annot"><span class="annottext">Addr#
-&gt; Addr# -&gt; State# RealWorld -&gt; (# State# RealWorld, Int#, Int# #)
</span><a href="../../ghc-prim/src/GHC.Prim.Ext.html#asyncDoProc%23"><span class="hs-identifier hs-var">asyncDoProc#</span></a></span><span> </span><span class="annot"><span class="annottext">Addr#
</span><a href="#local-6989586621679554028"><span class="hs-identifier hs-var">proc</span></a></span><span> </span><span class="annot"><span class="annottext">Addr#
</span><a href="#local-6989586621679554027"><span class="hs-identifier hs-var">param</span></a></span><span> </span><span class="annot"><span class="annottext">State# RealWorld
</span><a href="#local-6989586621679554026"><span class="hs-identifier hs-var">s</span></a></span><span>  </span><span class="hs-keyword">of</span><span>
</span><span id="line-87"></span><span>               </span><span class="hs-special">(#</span><span> </span><span id="local-6989586621679554024"><span class="annot"><span class="annottext">State# RealWorld
</span><a href="#local-6989586621679554024"><span class="hs-identifier hs-var">s'</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621679554023"><span class="annot"><span class="annottext">Int#
</span><a href="#local-6989586621679554023"><span class="hs-identifier hs-var">_len#</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621679554022"><span class="annot"><span class="annottext">Int#
</span><a href="#local-6989586621679554022"><span class="hs-identifier hs-var">err#</span></a></span></span><span> </span><span class="hs-special">#)</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">(#</span><span> </span><span class="annot"><span class="annottext">State# RealWorld
</span><a href="#local-6989586621679554024"><span class="hs-identifier hs-var">s'</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">Int# -&gt; Int
</span><a href="../../ghc-prim/src/GHC.Types.html#I%23"><span class="hs-identifier hs-var">I#</span></a></span><span> </span><span class="annot"><span class="annottext">Int#
</span><a href="#local-6989586621679554022"><span class="hs-identifier hs-var">err#</span></a></span><span> </span><span class="hs-special">#)</span><span>
</span><span id="line-88"></span><span>
</span><span id="line-89"></span><span class="hs-comment">-- to aid the use of these primops by the IO Handle implementation,</span><span>
</span><span id="line-90"></span><span class="hs-comment">-- provide the following convenience funs:</span><span>
</span><span id="line-91"></span><span>
</span><span id="line-92"></span><span class="hs-comment">-- this better be a pinned byte array!</span><span>
</span><span id="line-93"></span><span class="annot"><a href="GHC.Conc.POSIX.html#asyncReadBA"><span class="hs-identifier hs-type">asyncReadBA</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#Int"><span class="hs-identifier hs-type">Int</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#Int"><span class="hs-identifier hs-type">Int</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#Int"><span class="hs-identifier hs-type">Int</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#Int"><span class="hs-identifier hs-type">Int</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Prim.html#MutableByteArray%23"><span class="hs-identifier hs-type">MutableByteArray#</span></a></span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Prim.html#RealWorld"><span class="hs-identifier hs-type">RealWorld</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#Int"><span class="hs-identifier hs-type">Int</span></a></span><span class="hs-special">,</span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#Int"><span class="hs-identifier hs-type">Int</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-94"></span><span id="asyncReadBA"><span class="annot"><span class="annottext">asyncReadBA :: Int
-&gt; Int
-&gt; Int
-&gt; Int
-&gt; MutableByteArray# RealWorld
-&gt; IO (Int, Int)
</span><a href="GHC.Conc.POSIX.html#asyncReadBA"><span class="hs-identifier hs-var hs-var">asyncReadBA</span></a></span></span><span> </span><span id="local-6989586621679554021"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679554021"><span class="hs-identifier hs-var">fd</span></a></span></span><span> </span><span id="local-6989586621679554020"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679554020"><span class="hs-identifier hs-var">isSock</span></a></span></span><span> </span><span id="local-6989586621679554019"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679554019"><span class="hs-identifier hs-var">len</span></a></span></span><span> </span><span id="local-6989586621679554018"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679554018"><span class="hs-identifier hs-var">off</span></a></span></span><span> </span><span id="local-6989586621679554017"><span class="annot"><span class="annottext">MutableByteArray# RealWorld
</span><a href="#local-6989586621679554017"><span class="hs-identifier hs-var">bufB</span></a></span></span><span> </span><span class="hs-glyph">=</span><span>
</span><span id="line-95"></span><span>  </span><span class="annot"><span class="annottext">Int -&gt; Int -&gt; Int -&gt; Ptr Any -&gt; IO (Int, Int)
forall a. Int -&gt; Int -&gt; Int -&gt; Ptr a -&gt; IO (Int, Int)
</span><a href="GHC.Conc.POSIX.html#asyncRead"><span class="hs-identifier hs-var">asyncRead</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679554021"><span class="hs-identifier hs-var">fd</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679554020"><span class="hs-identifier hs-var">isSock</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679554019"><span class="hs-identifier hs-var">len</span></a></span><span> </span><span class="hs-special">(</span><span class="hs-special">(</span><span class="annot"><span class="annottext">Addr# -&gt; Ptr Any
forall a. Addr# -&gt; Ptr a
</span><a href="GHC.Ptr.html#Ptr"><span class="hs-identifier hs-var">Ptr</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">ByteArray# -&gt; Addr#
</span><a href="../../ghc-prim/src/GHC.Prim.html#byteArrayContents%23"><span class="hs-identifier hs-var">byteArrayContents#</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">MutableByteArray# RealWorld -&gt; ByteArray#
forall (a :: TYPE 'UnliftedRep) (b :: TYPE 'UnliftedRep). a -&gt; b
</span><a href="Unsafe.Coerce.html#unsafeCoerceUnlifted"><span class="hs-identifier hs-var">unsafeCoerceUnlifted</span></a></span><span> </span><span class="annot"><span class="annottext">MutableByteArray# RealWorld
</span><a href="#local-6989586621679554017"><span class="hs-identifier hs-var">bufB</span></a></span><span class="hs-special">)</span><span class="hs-special">)</span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">Ptr Any -&gt; Int -&gt; Ptr Any
forall a b. Ptr a -&gt; Int -&gt; Ptr b
</span><a href="GHC.Ptr.html#plusPtr"><span class="hs-operator hs-var">`plusPtr`</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679554018"><span class="hs-identifier hs-var">off</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-96"></span><span>
</span><span id="line-97"></span><span class="annot"><a href="GHC.Conc.POSIX.html#asyncWriteBA"><span class="hs-identifier hs-type">asyncWriteBA</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#Int"><span class="hs-identifier hs-type">Int</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#Int"><span class="hs-identifier hs-type">Int</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#Int"><span class="hs-identifier hs-type">Int</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#Int"><span class="hs-identifier hs-type">Int</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Prim.html#MutableByteArray%23"><span class="hs-identifier hs-type">MutableByteArray#</span></a></span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Prim.html#RealWorld"><span class="hs-identifier hs-type">RealWorld</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#Int"><span class="hs-identifier hs-type">Int</span></a></span><span class="hs-special">,</span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#Int"><span class="hs-identifier hs-type">Int</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-98"></span><span id="asyncWriteBA"><span class="annot"><span class="annottext">asyncWriteBA :: Int
-&gt; Int
-&gt; Int
-&gt; Int
-&gt; MutableByteArray# RealWorld
-&gt; IO (Int, Int)
</span><a href="GHC.Conc.POSIX.html#asyncWriteBA"><span class="hs-identifier hs-var hs-var">asyncWriteBA</span></a></span></span><span> </span><span id="local-6989586621679554015"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679554015"><span class="hs-identifier hs-var">fd</span></a></span></span><span> </span><span id="local-6989586621679554014"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679554014"><span class="hs-identifier hs-var">isSock</span></a></span></span><span> </span><span id="local-6989586621679554013"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679554013"><span class="hs-identifier hs-var">len</span></a></span></span><span> </span><span id="local-6989586621679554012"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679554012"><span class="hs-identifier hs-var">off</span></a></span></span><span> </span><span id="local-6989586621679554011"><span class="annot"><span class="annottext">MutableByteArray# RealWorld
</span><a href="#local-6989586621679554011"><span class="hs-identifier hs-var">bufB</span></a></span></span><span> </span><span class="hs-glyph">=</span><span>
</span><span id="line-99"></span><span>  </span><span class="annot"><span class="annottext">Int -&gt; Int -&gt; Int -&gt; Ptr Any -&gt; IO (Int, Int)
forall a. Int -&gt; Int -&gt; Int -&gt; Ptr a -&gt; IO (Int, Int)
</span><a href="GHC.Conc.POSIX.html#asyncWrite"><span class="hs-identifier hs-var">asyncWrite</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679554015"><span class="hs-identifier hs-var">fd</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679554014"><span class="hs-identifier hs-var">isSock</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679554013"><span class="hs-identifier hs-var">len</span></a></span><span> </span><span class="hs-special">(</span><span class="hs-special">(</span><span class="annot"><span class="annottext">Addr# -&gt; Ptr Any
forall a. Addr# -&gt; Ptr a
</span><a href="GHC.Ptr.html#Ptr"><span class="hs-identifier hs-var">Ptr</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">ByteArray# -&gt; Addr#
</span><a href="../../ghc-prim/src/GHC.Prim.html#byteArrayContents%23"><span class="hs-identifier hs-var">byteArrayContents#</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">MutableByteArray# RealWorld -&gt; ByteArray#
forall (a :: TYPE 'UnliftedRep) (b :: TYPE 'UnliftedRep). a -&gt; b
</span><a href="Unsafe.Coerce.html#unsafeCoerceUnlifted"><span class="hs-identifier hs-var">unsafeCoerceUnlifted</span></a></span><span> </span><span class="annot"><span class="annottext">MutableByteArray# RealWorld
</span><a href="#local-6989586621679554011"><span class="hs-identifier hs-var">bufB</span></a></span><span class="hs-special">)</span><span class="hs-special">)</span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">Ptr Any -&gt; Int -&gt; Ptr Any
forall a b. Ptr a -&gt; Int -&gt; Ptr b
</span><a href="GHC.Ptr.html#plusPtr"><span class="hs-operator hs-var">`plusPtr`</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679554012"><span class="hs-identifier hs-var">off</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-100"></span><span>
</span><span id="line-101"></span><span class="hs-comment">-- ----------------------------------------------------------------------------</span><span>
</span><span id="line-102"></span><span class="hs-comment">-- Threaded RTS implementation of threadDelay</span><span>
</span><span id="line-103"></span><span>
</span><span id="line-104"></span><span class="hs-comment">-- | Suspends the current thread for a given number of microseconds</span><span>
</span><span id="line-105"></span><span class="hs-comment">-- (GHC only).</span><span>
</span><span id="line-106"></span><span class="hs-comment">--</span><span>
</span><span id="line-107"></span><span class="hs-comment">-- There is no guarantee that the thread will be rescheduled promptly</span><span>
</span><span id="line-108"></span><span class="hs-comment">-- when the delay has expired, but the thread will never continue to</span><span>
</span><span id="line-109"></span><span class="hs-comment">-- run /earlier/ than specified.</span><span>
</span><span id="line-110"></span><span class="hs-comment">--</span><span>
</span><span id="line-111"></span><span class="annot"><a href="GHC.Conc.POSIX.html#threadDelay"><span class="hs-identifier hs-type">threadDelay</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#Int"><span class="hs-identifier hs-type">Int</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span><span>
</span><span id="line-112"></span><span id="threadDelay"><span class="annot"><span class="annottext">threadDelay :: Int -&gt; IO ()
</span><a href="GHC.Conc.POSIX.html#threadDelay"><span class="hs-identifier hs-var hs-var">threadDelay</span></a></span></span><span> </span><span id="local-6989586621679554010"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679554010"><span class="hs-identifier hs-var">time</span></a></span></span><span>
</span><span id="line-113"></span><span>  </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="GHC.Conc.POSIX.html#threaded"><span class="hs-identifier hs-var">threaded</span></a></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Int -&gt; IO ()
</span><a href="GHC.Conc.POSIX.html#waitForDelayEvent"><span class="hs-identifier hs-var">waitForDelayEvent</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679554010"><span class="hs-identifier hs-var">time</span></a></span><span>
</span><span id="line-114"></span><span>  </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="GHC.Base.html#otherwise"><span class="hs-identifier hs-var">otherwise</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">(State# RealWorld -&gt; (# State# RealWorld, () #)) -&gt; IO ()
forall a. (State# RealWorld -&gt; (# State# RealWorld, a #)) -&gt; IO a
</span><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-var">IO</span></a></span><span> </span><span class="annot"><span class="annottext">((State# RealWorld -&gt; (# State# RealWorld, () #)) -&gt; IO ())
-&gt; (State# RealWorld -&gt; (# State# RealWorld, () #)) -&gt; IO ()
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="hs-glyph">\</span><span id="local-6989586621679554007"><span class="annot"><span class="annottext">State# RealWorld
</span><a href="#local-6989586621679554007"><span class="hs-identifier hs-var">s</span></a></span></span><span> </span><span class="hs-glyph">-&gt;</span><span>
</span><span id="line-115"></span><span>        </span><span class="hs-keyword">case</span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679554010"><span class="hs-identifier hs-var">time</span></a></span><span> </span><span class="hs-keyword">of</span><span> </span><span class="hs-special">{</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#I%23"><span class="hs-identifier hs-type">I#</span></a></span><span> </span><span id="local-6989586621679554006"><span class="annot"><span class="annottext">Int#
</span><a href="#local-6989586621679554006"><span class="hs-identifier hs-var">time#</span></a></span></span><span> </span><span class="hs-glyph">-&gt;</span><span>
</span><span id="line-116"></span><span>        </span><span class="hs-keyword">case</span><span> </span><span class="annot"><span class="annottext">Int# -&gt; State# RealWorld -&gt; State# RealWorld
forall d. Int# -&gt; State# d -&gt; State# d
</span><a href="../../ghc-prim/src/GHC.Prim.html#delay%23"><span class="hs-identifier hs-var">delay#</span></a></span><span> </span><span class="annot"><span class="annottext">Int#
</span><a href="#local-6989586621679554006"><span class="hs-identifier hs-var">time#</span></a></span><span> </span><span class="annot"><span class="annottext">State# RealWorld
</span><a href="#local-6989586621679554007"><span class="hs-identifier hs-var">s</span></a></span><span> </span><span class="hs-keyword">of</span><span> </span><span class="hs-special">{</span><span> </span><span id="local-6989586621679554005"><span class="annot"><span class="annottext">State# RealWorld
</span><a href="#local-6989586621679554005"><span class="hs-identifier hs-var">s'</span></a></span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">(#</span><span> </span><span class="annot"><span class="annottext">State# RealWorld
</span><a href="#local-6989586621679554005"><span class="hs-identifier hs-var">s'</span></a></span><span class="hs-special">,</span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span><span> </span><span class="hs-special">#)</span><span>
</span><span id="line-117"></span><span>        </span><span class="hs-special">}</span><span class="hs-special">}</span><span>
</span><span id="line-118"></span><span>
</span><span id="line-119"></span><span class="hs-comment">-- | Set the value of returned TVar to True after a given number of</span><span>
</span><span id="line-120"></span><span class="hs-comment">-- microseconds. The caveats associated with threadDelay also apply.</span><span>
</span><span id="line-121"></span><span class="hs-comment">--</span><span>
</span><span id="line-122"></span><span class="annot"><a href="GHC.Conc.POSIX.html#registerDelay"><span class="hs-identifier hs-type">registerDelay</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#Int"><span class="hs-identifier hs-type">Int</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Conc.Sync.html#TVar"><span class="hs-identifier hs-type">TVar</span></a></span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#Bool"><span class="hs-identifier hs-type">Bool</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-123"></span><span id="registerDelay"><span class="annot"><span class="annottext">registerDelay :: Int -&gt; IO (TVar Bool)
</span><a href="GHC.Conc.POSIX.html#registerDelay"><span class="hs-identifier hs-var hs-var">registerDelay</span></a></span></span><span> </span><span id="local-6989586621679554004"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679554004"><span class="hs-identifier hs-var">usecs</span></a></span></span><span>
</span><span id="line-124"></span><span>  </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="GHC.Conc.POSIX.html#threaded"><span class="hs-identifier hs-var">threaded</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Int -&gt; IO (TVar Bool)
</span><a href="GHC.Conc.POSIX.html#waitForDelayEventSTM"><span class="hs-identifier hs-var">waitForDelayEventSTM</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679554004"><span class="hs-identifier hs-var">usecs</span></a></span><span>
</span><span id="line-125"></span><span>  </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="GHC.Base.html#otherwise"><span class="hs-identifier hs-var">otherwise</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">[Char] -&gt; IO (TVar Bool)
forall a. [Char] -&gt; a
</span><a href="GHC.Err.html#errorWithoutStackTrace"><span class="hs-identifier hs-var">errorWithoutStackTrace</span></a></span><span> </span><span class="annot"><span class="annottext">[Char]
</span><span class="hs-string">&quot;registerDelay: requires -threaded&quot;</span></span><span>
</span><span id="line-126"></span><span>
</span><span id="line-127"></span><span class="hs-keyword">foreign</span><span> </span><span class="hs-keyword">import</span><span> </span><span class="annot"><span class="hs-keyword">ccall</span></span><span> </span><span class="annot"><span class="hs-keyword">unsafe</span></span><span> </span><span class="annot"><span class="hs-string">&quot;rtsSupportsBoundThreads&quot;</span></span><span> </span><span id="threaded"><span class="annot"><a href="GHC.Conc.POSIX.html#threaded"><span class="hs-identifier hs-var">threaded</span></a></span></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#Bool"><span class="hs-identifier hs-type">Bool</span></a></span><span>
</span><span id="line-128"></span><span>
</span><span id="line-129"></span><span class="annot"><a href="GHC.Conc.POSIX.html#waitForDelayEvent"><span class="hs-identifier hs-type">waitForDelayEvent</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#Int"><span class="hs-identifier hs-type">Int</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span><span>
</span><span id="line-130"></span><span id="waitForDelayEvent"><span class="annot"><span class="annottext">waitForDelayEvent :: Int -&gt; IO ()
</span><a href="GHC.Conc.POSIX.html#waitForDelayEvent"><span class="hs-identifier hs-var hs-var">waitForDelayEvent</span></a></span></span><span> </span><span id="local-6989586621679554001"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679554001"><span class="hs-identifier hs-var">usecs</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-131"></span><span>  </span><span id="local-6989586621679554000"><span class="annot"><span class="annottext">MVar ()
</span><a href="#local-6989586621679554000"><span class="hs-identifier hs-var">m</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">IO (MVar ())
forall a. IO (MVar a)
</span><a href="GHC.MVar.html#newEmptyMVar"><span class="hs-identifier hs-var">newEmptyMVar</span></a></span><span>
</span><span id="line-132"></span><span>  </span><span id="local-6989586621679553998"><span class="annot"><span class="annottext">NSecs
</span><a href="#local-6989586621679553998"><span class="hs-identifier hs-var">target</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">Int -&gt; IO NSecs
</span><a href="GHC.Conc.POSIX.html#calculateTarget"><span class="hs-identifier hs-var">calculateTarget</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679554001"><span class="hs-identifier hs-var">usecs</span></a></span><span>
</span><span id="line-133"></span><span>  </span><span class="annot"><span class="annottext">([DelayReq], [DelayReq])
</span><span class="hs-identifier">_</span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">IORef [DelayReq]
-&gt; ([DelayReq] -&gt; [DelayReq]) -&gt; IO ([DelayReq], [DelayReq])
forall a. IORef a -&gt; (a -&gt; a) -&gt; IO (a, a)
</span><a href="GHC.IORef.html#atomicModifyIORef%27_"><span class="hs-identifier hs-var">atomicModifyIORef'_</span></a></span><span> </span><span class="annot"><span class="annottext">IORef [DelayReq]
</span><a href="GHC.Conc.POSIX.html#pendingDelays"><span class="hs-identifier hs-var">pendingDelays</span></a></span><span> </span><span class="hs-special">(</span><span class="hs-glyph">\</span><span id="local-6989586621679553994"><span class="annot"><span class="annottext">[DelayReq]
</span><a href="#local-6989586621679553994"><span class="hs-identifier hs-var">xs</span></a></span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">NSecs -&gt; MVar () -&gt; DelayReq
</span><a href="GHC.Conc.POSIX.html#Delay"><span class="hs-identifier hs-var">Delay</span></a></span><span> </span><span class="annot"><span class="annottext">NSecs
</span><a href="#local-6989586621679553998"><span class="hs-identifier hs-var">target</span></a></span><span> </span><span class="annot"><span class="annottext">MVar ()
</span><a href="#local-6989586621679554000"><span class="hs-identifier hs-var">m</span></a></span><span> </span><span class="annot"><span class="annottext">DelayReq -&gt; [DelayReq] -&gt; [DelayReq]
forall a. a -&gt; [a] -&gt; [a]
</span><a href="../../ghc-prim/src/GHC.Types.html#%3A"><span class="hs-glyph hs-var">:</span></a></span><span> </span><span class="annot"><span class="annottext">[DelayReq]
</span><a href="#local-6989586621679553994"><span class="hs-identifier hs-var">xs</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-134"></span><span>  </span><span class="annot"><span class="annottext">IO ()
</span><a href="GHC.Conc.POSIX.html#prodServiceThread"><span class="hs-identifier hs-var">prodServiceThread</span></a></span><span>
</span><span id="line-135"></span><span>  </span><span class="annot"><span class="annottext">MVar () -&gt; IO ()
forall a. MVar a -&gt; IO a
</span><a href="GHC.MVar.html#takeMVar"><span class="hs-identifier hs-var">takeMVar</span></a></span><span> </span><span class="annot"><span class="annottext">MVar ()
</span><a href="#local-6989586621679554000"><span class="hs-identifier hs-var">m</span></a></span><span>
</span><span id="line-136"></span><span>
</span><span id="line-137"></span><span class="hs-comment">-- Delays for use in STM</span><span>
</span><span id="line-138"></span><span class="annot"><a href="GHC.Conc.POSIX.html#waitForDelayEventSTM"><span class="hs-identifier hs-type">waitForDelayEventSTM</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#Int"><span class="hs-identifier hs-type">Int</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Conc.Sync.html#TVar"><span class="hs-identifier hs-type">TVar</span></a></span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#Bool"><span class="hs-identifier hs-type">Bool</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-139"></span><span id="waitForDelayEventSTM"><span class="annot"><span class="annottext">waitForDelayEventSTM :: Int -&gt; IO (TVar Bool)
</span><a href="GHC.Conc.POSIX.html#waitForDelayEventSTM"><span class="hs-identifier hs-var hs-var">waitForDelayEventSTM</span></a></span></span><span> </span><span id="local-6989586621679553990"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679553990"><span class="hs-identifier hs-var">usecs</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-140"></span><span>   </span><span id="local-6989586621679553989"><span class="annot"><span class="annottext">TVar Bool
</span><a href="#local-6989586621679553989"><span class="hs-identifier hs-var">t</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">STM (TVar Bool) -&gt; IO (TVar Bool)
forall a. STM a -&gt; IO a
</span><a href="GHC.Conc.Sync.html#atomically"><span class="hs-identifier hs-var">atomically</span></a></span><span> </span><span class="annot"><span class="annottext">(STM (TVar Bool) -&gt; IO (TVar Bool))
-&gt; STM (TVar Bool) -&gt; IO (TVar Bool)
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="annot"><span class="annottext">Bool -&gt; STM (TVar Bool)
forall a. a -&gt; STM (TVar a)
</span><a href="GHC.Conc.Sync.html#newTVar"><span class="hs-identifier hs-var">newTVar</span></a></span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="../../ghc-prim/src/GHC.Types.html#False"><span class="hs-identifier hs-var">False</span></a></span><span>
</span><span id="line-141"></span><span>   </span><span id="local-6989586621679553986"><span class="annot"><span class="annottext">NSecs
</span><a href="#local-6989586621679553986"><span class="hs-identifier hs-var">target</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">Int -&gt; IO NSecs
</span><a href="GHC.Conc.POSIX.html#calculateTarget"><span class="hs-identifier hs-var">calculateTarget</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679553990"><span class="hs-identifier hs-var">usecs</span></a></span><span>
</span><span id="line-142"></span><span>   </span><span class="annot"><span class="annottext">([DelayReq], [DelayReq])
</span><span class="hs-identifier">_</span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">IORef [DelayReq]
-&gt; ([DelayReq] -&gt; [DelayReq]) -&gt; IO ([DelayReq], [DelayReq])
forall a. IORef a -&gt; (a -&gt; a) -&gt; IO (a, a)
</span><a href="GHC.IORef.html#atomicModifyIORef%27_"><span class="hs-identifier hs-var">atomicModifyIORef'_</span></a></span><span> </span><span class="annot"><span class="annottext">IORef [DelayReq]
</span><a href="GHC.Conc.POSIX.html#pendingDelays"><span class="hs-identifier hs-var">pendingDelays</span></a></span><span> </span><span class="hs-special">(</span><span class="hs-glyph">\</span><span id="local-6989586621679553985"><span class="annot"><span class="annottext">[DelayReq]
</span><a href="#local-6989586621679553985"><span class="hs-identifier hs-var">xs</span></a></span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">NSecs -&gt; TVar Bool -&gt; DelayReq
</span><a href="GHC.Conc.POSIX.html#DelaySTM"><span class="hs-identifier hs-var">DelaySTM</span></a></span><span> </span><span class="annot"><span class="annottext">NSecs
</span><a href="#local-6989586621679553986"><span class="hs-identifier hs-var">target</span></a></span><span> </span><span class="annot"><span class="annottext">TVar Bool
</span><a href="#local-6989586621679553989"><span class="hs-identifier hs-var">t</span></a></span><span> </span><span class="annot"><span class="annottext">DelayReq -&gt; [DelayReq] -&gt; [DelayReq]
forall a. a -&gt; [a] -&gt; [a]
</span><a href="../../ghc-prim/src/GHC.Types.html#%3A"><span class="hs-glyph hs-var">:</span></a></span><span> </span><span class="annot"><span class="annottext">[DelayReq]
</span><a href="#local-6989586621679553985"><span class="hs-identifier hs-var">xs</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-143"></span><span>   </span><span class="annot"><span class="annottext">IO ()
</span><a href="GHC.Conc.POSIX.html#prodServiceThread"><span class="hs-identifier hs-var">prodServiceThread</span></a></span><span>
</span><span id="line-144"></span><span>   </span><span class="annot"><span class="annottext">TVar Bool -&gt; IO (TVar Bool)
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="annot"><span class="annottext">TVar Bool
</span><a href="#local-6989586621679553989"><span class="hs-identifier hs-var">t</span></a></span><span>
</span><span id="line-145"></span><span>
</span><span id="line-146"></span><span class="annot"><a href="GHC.Conc.POSIX.html#calculateTarget"><span class="hs-identifier hs-type">calculateTarget</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#Int"><span class="hs-identifier hs-type">Int</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="annot"><a href="GHC.Conc.POSIX.html#USecs"><span class="hs-identifier hs-type">USecs</span></a></span><span>
</span><span id="line-147"></span><span id="calculateTarget"><span class="annot"><span class="annottext">calculateTarget :: Int -&gt; IO NSecs
</span><a href="GHC.Conc.POSIX.html#calculateTarget"><span class="hs-identifier hs-var hs-var">calculateTarget</span></a></span></span><span> </span><span id="local-6989586621679553982"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679553982"><span class="hs-identifier hs-var">usecs</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-148"></span><span>    </span><span id="local-6989586621679553981"><span class="annot"><span class="annottext">NSecs
</span><a href="#local-6989586621679553981"><span class="hs-identifier hs-var">now</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">IO NSecs
</span><a href="GHC.Conc.POSIX.html#getMonotonicUSec"><span class="hs-identifier hs-var">getMonotonicUSec</span></a></span><span>
</span><span id="line-149"></span><span>    </span><span class="annot"><span class="annottext">NSecs -&gt; IO NSecs
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="annot"><span class="annottext">(NSecs -&gt; IO NSecs) -&gt; NSecs -&gt; IO NSecs
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="annot"><span class="annottext">NSecs
</span><a href="#local-6989586621679553981"><span class="hs-identifier hs-var">now</span></a></span><span> </span><span class="annot"><span class="annottext">NSecs -&gt; NSecs -&gt; NSecs
forall a. Num a =&gt; a -&gt; a -&gt; a
</span><a href="GHC.Num.html#%2B"><span class="hs-operator hs-var">+</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Int -&gt; NSecs
forall a b. (Integral a, Num b) =&gt; a -&gt; b
</span><a href="GHC.Real.html#fromIntegral"><span class="hs-identifier hs-var">fromIntegral</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679553982"><span class="hs-identifier hs-var">usecs</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-150"></span><span>
</span><span id="line-151"></span><span class="hs-keyword">data</span><span> </span><span id="DelayReq"><span class="annot"><a href="GHC.Conc.POSIX.html#DelayReq"><span class="hs-identifier hs-var">DelayReq</span></a></span></span><span>
</span><span id="line-152"></span><span>  </span><span class="hs-glyph">=</span><span> </span><span id="Delay"><span class="annot"><a href="GHC.Conc.POSIX.html#Delay"><span class="hs-identifier hs-var">Delay</span></a></span></span><span>    </span><span class="hs-pragma">{-# UNPACK</span><span> </span><span class="hs-pragma">#-}</span><span> </span><span class="hs-glyph">!</span><span class="annot"><a href="GHC.Conc.POSIX.html#USecs"><span class="hs-identifier hs-type">USecs</span></a></span><span> </span><span class="hs-pragma">{-# UNPACK</span><span> </span><span class="hs-pragma">#-}</span><span> </span><span class="hs-glyph">!</span><span class="hs-special">(</span><span class="annot"><a href="GHC.MVar.html#MVar"><span class="hs-identifier hs-type">MVar</span></a></span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span><span class="hs-special">)</span><span>
</span><span id="line-153"></span><span>  </span><span class="hs-glyph">|</span><span> </span><span id="DelaySTM"><span class="annot"><a href="GHC.Conc.POSIX.html#DelaySTM"><span class="hs-identifier hs-var">DelaySTM</span></a></span></span><span> </span><span class="hs-pragma">{-# UNPACK</span><span> </span><span class="hs-pragma">#-}</span><span> </span><span class="hs-glyph">!</span><span class="annot"><a href="GHC.Conc.POSIX.html#USecs"><span class="hs-identifier hs-type">USecs</span></a></span><span> </span><span class="hs-pragma">{-# UNPACK</span><span> </span><span class="hs-pragma">#-}</span><span> </span><span class="hs-glyph">!</span><span class="hs-special">(</span><span class="annot"><a href="GHC.Conc.Sync.html#TVar"><span class="hs-identifier hs-type">TVar</span></a></span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#Bool"><span class="hs-identifier hs-type">Bool</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-154"></span><span>
</span><span id="line-155"></span><span class="hs-pragma">{-# NOINLINE</span><span> </span><span class="annot"><a href="GHC.Conc.POSIX.html#pendingDelays"><span class="hs-pragma hs-type">pendingDelays</span></a></span><span> </span><span class="hs-pragma">#-}</span><span>
</span><span id="line-156"></span><span class="annot"><a href="GHC.Conc.POSIX.html#pendingDelays"><span class="hs-identifier hs-type">pendingDelays</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.IORef.html#IORef"><span class="hs-identifier hs-type">IORef</span></a></span><span> </span><span class="hs-special">[</span><span class="annot"><a href="GHC.Conc.POSIX.html#DelayReq"><span class="hs-identifier hs-type">DelayReq</span></a></span><span class="hs-special">]</span><span>
</span><span id="line-157"></span><span id="pendingDelays"><span class="annot"><span class="annottext">pendingDelays :: IORef [DelayReq]
</span><a href="GHC.Conc.POSIX.html#pendingDelays"><span class="hs-identifier hs-var hs-var">pendingDelays</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">IO (IORef [DelayReq]) -&gt; IORef [DelayReq]
forall a. IO a -&gt; a
</span><a href="GHC.IO.Unsafe.html#unsafePerformIO"><span class="hs-identifier hs-var">unsafePerformIO</span></a></span><span> </span><span class="annot"><span class="annottext">(IO (IORef [DelayReq]) -&gt; IORef [DelayReq])
-&gt; IO (IORef [DelayReq]) -&gt; IORef [DelayReq]
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-158"></span><span>   </span><span id="local-6989586621679553978"><span class="annot"><span class="annottext">IORef [DelayReq]
</span><a href="#local-6989586621679553978"><span class="hs-identifier hs-var">m</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">[DelayReq] -&gt; IO (IORef [DelayReq])
forall a. a -&gt; IO (IORef a)
</span><a href="GHC.IORef.html#newIORef"><span class="hs-identifier hs-var">newIORef</span></a></span><span> </span><span class="hs-special">[</span><span class="hs-special">]</span><span>
</span><span id="line-159"></span><span>   </span><span class="annot"><span class="annottext">IORef [DelayReq]
-&gt; (Ptr (IORef [DelayReq]) -&gt; IO (Ptr (IORef [DelayReq])))
-&gt; IO (IORef [DelayReq])
forall a. a -&gt; (Ptr a -&gt; IO (Ptr a)) -&gt; IO a
</span><a href="GHC.Conc.Sync.html#sharedCAF"><span class="hs-identifier hs-var">sharedCAF</span></a></span><span> </span><span class="annot"><span class="annottext">IORef [DelayReq]
</span><a href="#local-6989586621679553978"><span class="hs-identifier hs-var">m</span></a></span><span> </span><span class="annot"><span class="annottext">Ptr (IORef [DelayReq]) -&gt; IO (Ptr (IORef [DelayReq]))
forall a. Ptr a -&gt; IO (Ptr a)
</span><a href="GHC.Conc.POSIX.html#getOrSetGHCConcWindowsPendingDelaysStore"><span class="hs-identifier hs-var">getOrSetGHCConcWindowsPendingDelaysStore</span></a></span><span>
</span><span id="line-160"></span><span>
</span><span id="line-161"></span><span id="local-6989586621679554150"><span class="hs-keyword">foreign</span><span> </span><span class="hs-keyword">import</span><span> </span><span class="annot"><span class="hs-keyword">ccall</span></span><span> </span><span class="annot"><span class="hs-keyword">unsafe</span></span><span> </span><span class="annot"><span class="hs-string">&quot;getOrSetGHCConcWindowsPendingDelaysStore&quot;</span></span><span>
</span><span id="line-162"></span><span>    </span><span id="getOrSetGHCConcWindowsPendingDelaysStore"><span class="annot"><a href="GHC.Conc.POSIX.html#getOrSetGHCConcWindowsPendingDelaysStore"><span class="hs-identifier hs-var">getOrSetGHCConcWindowsPendingDelaysStore</span></a></span></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Ptr.html#Ptr"><span class="hs-identifier hs-type">Ptr</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679554150"><span class="hs-identifier hs-type">a</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Ptr.html#Ptr"><span class="hs-identifier hs-type">Ptr</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679554150"><span class="hs-identifier hs-type">a</span></a></span><span class="hs-special">)</span></span><span>
</span><span id="line-163"></span><span>
</span><span id="line-164"></span><span class="hs-pragma">{-# NOINLINE</span><span> </span><span class="annot"><a href="GHC.Conc.POSIX.html#ioManagerThread"><span class="hs-pragma hs-type">ioManagerThread</span></a></span><span> </span><span class="hs-pragma">#-}</span><span>
</span><span id="line-165"></span><span class="annot"><a href="GHC.Conc.POSIX.html#ioManagerThread"><span class="hs-identifier hs-type">ioManagerThread</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.MVar.html#MVar"><span class="hs-identifier hs-type">MVar</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Maybe.html#Maybe"><span class="hs-identifier hs-type">Maybe</span></a></span><span> </span><span class="annot"><a href="GHC.Conc.Sync.html#ThreadId"><span class="hs-identifier hs-type">ThreadId</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-166"></span><span id="ioManagerThread"><span class="annot"><span class="annottext">ioManagerThread :: MVar (Maybe ThreadId)
</span><a href="GHC.Conc.POSIX.html#ioManagerThread"><span class="hs-identifier hs-var hs-var">ioManagerThread</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">IO (MVar (Maybe ThreadId)) -&gt; MVar (Maybe ThreadId)
forall a. IO a -&gt; a
</span><a href="GHC.IO.Unsafe.html#unsafePerformIO"><span class="hs-identifier hs-var">unsafePerformIO</span></a></span><span> </span><span class="annot"><span class="annottext">(IO (MVar (Maybe ThreadId)) -&gt; MVar (Maybe ThreadId))
-&gt; IO (MVar (Maybe ThreadId)) -&gt; MVar (Maybe ThreadId)
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-167"></span><span>   </span><span id="local-6989586621679553973"><span class="annot"><span class="annottext">MVar (Maybe ThreadId)
</span><a href="#local-6989586621679553973"><span class="hs-identifier hs-var">m</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">Maybe ThreadId -&gt; IO (MVar (Maybe ThreadId))
forall a. a -&gt; IO (MVar a)
</span><a href="GHC.MVar.html#newMVar"><span class="hs-identifier hs-var">newMVar</span></a></span><span> </span><span class="annot"><span class="annottext">Maybe ThreadId
forall a. Maybe a
</span><a href="GHC.Maybe.html#Nothing"><span class="hs-identifier hs-var">Nothing</span></a></span><span>
</span><span id="line-168"></span><span>   </span><span class="annot"><span class="annottext">MVar (Maybe ThreadId)
-&gt; (Ptr (MVar (Maybe ThreadId))
    -&gt; IO (Ptr (MVar (Maybe ThreadId))))
-&gt; IO (MVar (Maybe ThreadId))
forall a. a -&gt; (Ptr a -&gt; IO (Ptr a)) -&gt; IO a
</span><a href="GHC.Conc.Sync.html#sharedCAF"><span class="hs-identifier hs-var">sharedCAF</span></a></span><span> </span><span class="annot"><span class="annottext">MVar (Maybe ThreadId)
</span><a href="#local-6989586621679553973"><span class="hs-identifier hs-var">m</span></a></span><span> </span><span class="annot"><span class="annottext">Ptr (MVar (Maybe ThreadId)) -&gt; IO (Ptr (MVar (Maybe ThreadId)))
forall a. Ptr a -&gt; IO (Ptr a)
</span><a href="GHC.Conc.POSIX.html#getOrSetGHCConcWindowsIOManagerThreadStore"><span class="hs-identifier hs-var">getOrSetGHCConcWindowsIOManagerThreadStore</span></a></span><span>
</span><span id="line-169"></span><span>
</span><span id="line-170"></span><span id="local-6989586621679553970"><span class="hs-keyword">foreign</span><span> </span><span class="hs-keyword">import</span><span> </span><span class="annot"><span class="hs-keyword">ccall</span></span><span> </span><span class="annot"><span class="hs-keyword">unsafe</span></span><span> </span><span class="annot"><span class="hs-string">&quot;getOrSetGHCConcWindowsIOManagerThreadStore&quot;</span></span><span>
</span><span id="line-171"></span><span>    </span><span id="getOrSetGHCConcWindowsIOManagerThreadStore"><span class="annot"><a href="GHC.Conc.POSIX.html#getOrSetGHCConcWindowsIOManagerThreadStore"><span class="hs-identifier hs-var">getOrSetGHCConcWindowsIOManagerThreadStore</span></a></span></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Ptr.html#Ptr"><span class="hs-identifier hs-type">Ptr</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679553970"><span class="hs-identifier hs-type">a</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Ptr.html#Ptr"><span class="hs-identifier hs-type">Ptr</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679553970"><span class="hs-identifier hs-type">a</span></a></span><span class="hs-special">)</span></span><span>
</span><span id="line-172"></span><span>
</span><span id="line-173"></span><span class="annot"><a href="GHC.Conc.POSIX.html#ensureIOManagerIsRunning"><span class="hs-identifier hs-type">ensureIOManagerIsRunning</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span><span>
</span><span id="line-174"></span><span id="ensureIOManagerIsRunning"><span class="annot"><span class="annottext">ensureIOManagerIsRunning :: IO ()
</span><a href="GHC.Conc.POSIX.html#ensureIOManagerIsRunning"><span class="hs-identifier hs-var hs-var">ensureIOManagerIsRunning</span></a></span></span><span>
</span><span id="line-175"></span><span>  </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="GHC.Conc.POSIX.html#threaded"><span class="hs-identifier hs-var">threaded</span></a></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">IO ()
</span><a href="GHC.Conc.POSIX.html#startIOManagerThread"><span class="hs-identifier hs-var">startIOManagerThread</span></a></span><span>
</span><span id="line-176"></span><span>  </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="GHC.Base.html#otherwise"><span class="hs-identifier hs-var">otherwise</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">() -&gt; IO ()
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span><span>
</span><span id="line-177"></span><span>
</span><span id="line-178"></span><span class="annot"><a href="GHC.Conc.POSIX.html#interruptIOManager"><span class="hs-identifier hs-type">interruptIOManager</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span><span>
</span><span id="line-179"></span><span id="interruptIOManager"><span class="annot"><span class="annottext">interruptIOManager :: IO ()
</span><a href="GHC.Conc.POSIX.html#interruptIOManager"><span class="hs-identifier hs-var hs-var">interruptIOManager</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">() -&gt; IO ()
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span><span>
</span><span id="line-180"></span><span>
</span><span id="line-181"></span><span class="annot"><a href="GHC.Conc.POSIX.html#startIOManagerThread"><span class="hs-identifier hs-type">startIOManagerThread</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span><span>
</span><span id="line-182"></span><span id="startIOManagerThread"><span class="annot"><span class="annottext">startIOManagerThread :: IO ()
</span><a href="GHC.Conc.POSIX.html#startIOManagerThread"><span class="hs-identifier hs-var hs-var">startIOManagerThread</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-183"></span><span>  </span><span class="annot"><span class="annottext">MVar (Maybe ThreadId)
-&gt; (Maybe ThreadId -&gt; IO (Maybe ThreadId)) -&gt; IO ()
forall a. MVar a -&gt; (a -&gt; IO a) -&gt; IO ()
</span><a href="GHC.Conc.Sync.html#modifyMVar_"><span class="hs-identifier hs-var">modifyMVar_</span></a></span><span> </span><span class="annot"><span class="annottext">MVar (Maybe ThreadId)
</span><a href="GHC.Conc.POSIX.html#ioManagerThread"><span class="hs-identifier hs-var">ioManagerThread</span></a></span><span> </span><span class="annot"><span class="annottext">((Maybe ThreadId -&gt; IO (Maybe ThreadId)) -&gt; IO ())
-&gt; (Maybe ThreadId -&gt; IO (Maybe ThreadId)) -&gt; IO ()
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="hs-glyph">\</span><span id="local-6989586621679553967"><span class="annot"><span class="annottext">Maybe ThreadId
</span><a href="#local-6989586621679553967"><span class="hs-identifier hs-var">old</span></a></span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-184"></span><span>    </span><span class="hs-keyword">let</span><span> </span><span id="local-6989586621679553963"><span class="annot"><span class="annottext">create :: IO (Maybe ThreadId)
</span><a href="#local-6989586621679553963"><span class="hs-identifier hs-var hs-var">create</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span> </span><span id="local-6989586621679553962"><span class="annot"><span class="annottext">ThreadId
</span><a href="#local-6989586621679553962"><span class="hs-identifier hs-var">t</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">IO () -&gt; IO ThreadId
</span><a href="GHC.Conc.Sync.html#forkIO"><span class="hs-identifier hs-var">forkIO</span></a></span><span> </span><span class="annot"><span class="annottext">IO ()
</span><a href="GHC.Conc.POSIX.html#ioManager"><span class="hs-identifier hs-var">ioManager</span></a></span><span class="hs-special">;</span><span>
</span><span id="line-185"></span><span>                    </span><span class="annot"><span class="annottext">ThreadId -&gt; [Char] -&gt; IO ()
</span><a href="GHC.Conc.Sync.html#labelThread"><span class="hs-identifier hs-var">labelThread</span></a></span><span> </span><span class="annot"><span class="annottext">ThreadId
</span><a href="#local-6989586621679553962"><span class="hs-identifier hs-var">t</span></a></span><span> </span><span class="annot"><span class="annottext">[Char]
</span><span class="hs-string">&quot;IOManagerThread&quot;</span></span><span class="hs-special">;</span><span>
</span><span id="line-186"></span><span>                    </span><span class="annot"><span class="annottext">Maybe ThreadId -&gt; IO (Maybe ThreadId)
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">ThreadId -&gt; Maybe ThreadId
forall a. a -&gt; Maybe a
</span><a href="GHC.Maybe.html#Just"><span class="hs-identifier hs-var">Just</span></a></span><span> </span><span class="annot"><span class="annottext">ThreadId
</span><a href="#local-6989586621679553962"><span class="hs-identifier hs-var">t</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-187"></span><span>    </span><span class="hs-keyword">case</span><span> </span><span class="annot"><span class="annottext">Maybe ThreadId
</span><a href="#local-6989586621679553967"><span class="hs-identifier hs-var">old</span></a></span><span> </span><span class="hs-keyword">of</span><span>
</span><span id="line-188"></span><span>      </span><span class="annot"><span class="annottext">Maybe ThreadId
</span><a href="GHC.Maybe.html#Nothing"><span class="hs-identifier hs-var">Nothing</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">IO (Maybe ThreadId)
</span><a href="#local-6989586621679553963"><span class="hs-identifier hs-var">create</span></a></span><span>
</span><span id="line-189"></span><span>      </span><span class="annot"><a href="GHC.Maybe.html#Just"><span class="hs-identifier hs-type">Just</span></a></span><span> </span><span id="local-6989586621679553958"><span class="annot"><span class="annottext">ThreadId
</span><a href="#local-6989586621679553958"><span class="hs-identifier hs-var">t</span></a></span></span><span>  </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-190"></span><span>        </span><span id="local-6989586621679553957"><span class="annot"><span class="annottext">ThreadStatus
</span><a href="#local-6989586621679553957"><span class="hs-identifier hs-var">s</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">ThreadId -&gt; IO ThreadStatus
</span><a href="GHC.Conc.Sync.html#threadStatus"><span class="hs-identifier hs-var">threadStatus</span></a></span><span> </span><span class="annot"><span class="annottext">ThreadId
</span><a href="#local-6989586621679553958"><span class="hs-identifier hs-var">t</span></a></span><span>
</span><span id="line-191"></span><span>        </span><span class="hs-keyword">case</span><span> </span><span class="annot"><span class="annottext">ThreadStatus
</span><a href="#local-6989586621679553957"><span class="hs-identifier hs-var">s</span></a></span><span> </span><span class="hs-keyword">of</span><span>
</span><span id="line-192"></span><span>          </span><span class="annot"><span class="annottext">ThreadStatus
</span><a href="GHC.Conc.Sync.html#ThreadFinished"><span class="hs-identifier hs-var">ThreadFinished</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">IO (Maybe ThreadId)
</span><a href="#local-6989586621679553963"><span class="hs-identifier hs-var">create</span></a></span><span>
</span><span id="line-193"></span><span>          </span><span class="annot"><span class="annottext">ThreadStatus
</span><a href="GHC.Conc.Sync.html#ThreadDied"><span class="hs-identifier hs-var">ThreadDied</span></a></span><span>     </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">IO (Maybe ThreadId)
</span><a href="#local-6989586621679553963"><span class="hs-identifier hs-var">create</span></a></span><span>
</span><span id="line-194"></span><span>          </span><span id="local-6989586621679553953"><span class="annot"><span class="annottext">ThreadStatus
</span><a href="#local-6989586621679553953"><span class="hs-identifier hs-var">_other</span></a></span></span><span>         </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">Maybe ThreadId -&gt; IO (Maybe ThreadId)
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">ThreadId -&gt; Maybe ThreadId
forall a. a -&gt; Maybe a
</span><a href="GHC.Maybe.html#Just"><span class="hs-identifier hs-var">Just</span></a></span><span> </span><span class="annot"><span class="annottext">ThreadId
</span><a href="#local-6989586621679553958"><span class="hs-identifier hs-var">t</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-195"></span><span>
</span><span id="line-196"></span><span class="annot"><a href="GHC.Conc.POSIX.html#insertDelay"><span class="hs-identifier hs-type">insertDelay</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Conc.POSIX.html#DelayReq"><span class="hs-identifier hs-type">DelayReq</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">[</span><span class="annot"><a href="GHC.Conc.POSIX.html#DelayReq"><span class="hs-identifier hs-type">DelayReq</span></a></span><span class="hs-special">]</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">[</span><span class="annot"><a href="GHC.Conc.POSIX.html#DelayReq"><span class="hs-identifier hs-type">DelayReq</span></a></span><span class="hs-special">]</span><span>
</span><span id="line-197"></span><span id="insertDelay"><span class="annot"><span class="annottext">insertDelay :: DelayReq -&gt; [DelayReq] -&gt; [DelayReq]
</span><a href="GHC.Conc.POSIX.html#insertDelay"><span class="hs-identifier hs-var hs-var">insertDelay</span></a></span></span><span> </span><span id="local-6989586621679553951"><span class="annot"><span class="annottext">DelayReq
</span><a href="#local-6989586621679553951"><span class="hs-identifier hs-var">d</span></a></span></span><span> </span><span class="hs-special">[</span><span class="hs-special">]</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-special">[</span><span class="annot"><span class="annottext">DelayReq
</span><a href="#local-6989586621679553951"><span class="hs-identifier hs-var">d</span></a></span><span class="hs-special">]</span><span>
</span><span id="line-198"></span><span class="annot"><a href="GHC.Conc.POSIX.html#insertDelay"><span class="hs-identifier hs-var">insertDelay</span></a></span><span> </span><span id="local-6989586621679553950"><span class="annot"><span class="annottext">DelayReq
</span><a href="#local-6989586621679553950"><span class="hs-identifier hs-var">d1</span></a></span></span><span> </span><span id="local-6989586621679553949"><span class="annot"><span class="annottext">ds :: [DelayReq]
</span><a href="#local-6989586621679553949"><span class="hs-identifier hs-var">ds</span></a></span></span><span class="hs-glyph">@</span><span class="hs-special">(</span><span id="local-6989586621679553948"><span class="annot"><span class="annottext">DelayReq
</span><a href="#local-6989586621679553948"><span class="hs-identifier hs-var">d2</span></a></span></span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#%3A"><span class="hs-glyph hs-type">:</span></a></span><span> </span><span id="local-6989586621679553947"><span class="annot"><span class="annottext">[DelayReq]
</span><a href="#local-6989586621679553947"><span class="hs-identifier hs-var">rest</span></a></span></span><span class="hs-special">)</span><span>
</span><span id="line-199"></span><span>  </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">DelayReq -&gt; NSecs
</span><a href="GHC.Conc.POSIX.html#delayTime"><span class="hs-identifier hs-var">delayTime</span></a></span><span> </span><span class="annot"><span class="annottext">DelayReq
</span><a href="#local-6989586621679553950"><span class="hs-identifier hs-var">d1</span></a></span><span> </span><span class="annot"><span class="annottext">NSecs -&gt; NSecs -&gt; Bool
forall a. Ord a =&gt; a -&gt; a -&gt; Bool
</span><a href="../../ghc-prim/src/GHC.Classes.html#%3C%3D"><span class="hs-operator hs-var">&lt;=</span></a></span><span> </span><span class="annot"><span class="annottext">DelayReq -&gt; NSecs
</span><a href="GHC.Conc.POSIX.html#delayTime"><span class="hs-identifier hs-var">delayTime</span></a></span><span> </span><span class="annot"><span class="annottext">DelayReq
</span><a href="#local-6989586621679553948"><span class="hs-identifier hs-var">d2</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">DelayReq
</span><a href="#local-6989586621679553950"><span class="hs-identifier hs-var">d1</span></a></span><span> </span><span class="annot"><span class="annottext">DelayReq -&gt; [DelayReq] -&gt; [DelayReq]
forall a. a -&gt; [a] -&gt; [a]
</span><a href="../../ghc-prim/src/GHC.Types.html#%3A"><span class="hs-glyph hs-var">:</span></a></span><span> </span><span class="annot"><span class="annottext">[DelayReq]
</span><a href="#local-6989586621679553949"><span class="hs-identifier hs-var">ds</span></a></span><span>
</span><span id="line-200"></span><span>  </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="GHC.Base.html#otherwise"><span class="hs-identifier hs-var">otherwise</span></a></span><span>                    </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">DelayReq
</span><a href="#local-6989586621679553948"><span class="hs-identifier hs-var">d2</span></a></span><span> </span><span class="annot"><span class="annottext">DelayReq -&gt; [DelayReq] -&gt; [DelayReq]
forall a. a -&gt; [a] -&gt; [a]
</span><a href="../../ghc-prim/src/GHC.Types.html#%3A"><span class="hs-glyph hs-var">:</span></a></span><span> </span><span class="annot"><span class="annottext">DelayReq -&gt; [DelayReq] -&gt; [DelayReq]
</span><a href="GHC.Conc.POSIX.html#insertDelay"><span class="hs-identifier hs-var">insertDelay</span></a></span><span> </span><span class="annot"><span class="annottext">DelayReq
</span><a href="#local-6989586621679553950"><span class="hs-identifier hs-var">d1</span></a></span><span> </span><span class="annot"><span class="annottext">[DelayReq]
</span><a href="#local-6989586621679553947"><span class="hs-identifier hs-var">rest</span></a></span><span>
</span><span id="line-201"></span><span>
</span><span id="line-202"></span><span class="annot"><a href="GHC.Conc.POSIX.html#delayTime"><span class="hs-identifier hs-type">delayTime</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Conc.POSIX.html#DelayReq"><span class="hs-identifier hs-type">DelayReq</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Conc.POSIX.html#USecs"><span class="hs-identifier hs-type">USecs</span></a></span><span>
</span><span id="line-203"></span><span id="delayTime"><span class="annot"><span class="annottext">delayTime :: DelayReq -&gt; NSecs
</span><a href="GHC.Conc.POSIX.html#delayTime"><span class="hs-identifier hs-var hs-var">delayTime</span></a></span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Conc.POSIX.html#Delay"><span class="hs-identifier hs-type">Delay</span></a></span><span> </span><span id="local-6989586621679553944"><span class="annot"><span class="annottext">NSecs
</span><a href="#local-6989586621679553944"><span class="hs-identifier hs-var">t</span></a></span></span><span> </span><span class="annot"><span class="annottext">MVar ()
</span><span class="hs-identifier">_</span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">NSecs
</span><a href="#local-6989586621679553944"><span class="hs-identifier hs-var">t</span></a></span><span>
</span><span id="line-204"></span><span class="annot"><a href="GHC.Conc.POSIX.html#delayTime"><span class="hs-identifier hs-var">delayTime</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Conc.POSIX.html#DelaySTM"><span class="hs-identifier hs-type">DelaySTM</span></a></span><span> </span><span id="local-6989586621679553943"><span class="annot"><span class="annottext">NSecs
</span><a href="#local-6989586621679553943"><span class="hs-identifier hs-var">t</span></a></span></span><span> </span><span class="annot"><span class="annottext">TVar Bool
</span><span class="hs-identifier">_</span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">NSecs
</span><a href="#local-6989586621679553943"><span class="hs-identifier hs-var">t</span></a></span><span>
</span><span id="line-205"></span><span>
</span><span id="line-206"></span><span class="hs-keyword">type</span><span> </span><span id="USecs"><span class="annot"><a href="GHC.Conc.POSIX.html#USecs"><span class="hs-identifier hs-var">USecs</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><a href="GHC.Word.html#Word64"><span class="hs-identifier hs-type">Word64</span></a></span><span>
</span><span id="line-207"></span><span class="hs-keyword">type</span><span> </span><span id="NSecs"><span class="annot"><a href="GHC.Conc.POSIX.html#NSecs"><span class="hs-identifier hs-var">NSecs</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><a href="GHC.Word.html#Word64"><span class="hs-identifier hs-type">Word64</span></a></span><span>
</span><span id="line-208"></span><span>
</span><span id="line-209"></span><span class="hs-keyword">foreign</span><span> </span><span class="hs-keyword">import</span><span> </span><span class="annot"><span class="hs-keyword">ccall</span></span><span> </span><span class="annot"><span class="hs-keyword">unsafe</span></span><span> </span><span class="annot"><span class="hs-string">&quot;getMonotonicNSec&quot;</span></span><span>
</span><span id="line-210"></span><span>  </span><span id="getMonotonicNSec"><span class="annot"><a href="GHC.Conc.POSIX.html#getMonotonicNSec"><span class="hs-identifier hs-var">getMonotonicNSec</span></a></span></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="annot"><a href="GHC.Conc.POSIX.html#NSecs"><span class="hs-identifier hs-type">NSecs</span></a></span><span>
</span><span id="line-211"></span><span>
</span><span id="line-212"></span><span class="annot"><a href="GHC.Conc.POSIX.html#getMonotonicUSec"><span class="hs-identifier hs-type">getMonotonicUSec</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="annot"><a href="GHC.Conc.POSIX.html#USecs"><span class="hs-identifier hs-type">USecs</span></a></span><span>
</span><span id="line-213"></span><span id="getMonotonicUSec"><span class="annot"><span class="annottext">getMonotonicUSec :: IO NSecs
</span><a href="GHC.Conc.POSIX.html#getMonotonicUSec"><span class="hs-identifier hs-var hs-var">getMonotonicUSec</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">(NSecs -&gt; NSecs) -&gt; IO NSecs -&gt; IO NSecs
forall (f :: * -&gt; *) a b. Functor f =&gt; (a -&gt; b) -&gt; f a -&gt; f b
</span><a href="GHC.Base.html#fmap"><span class="hs-identifier hs-var">fmap</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">NSecs -&gt; NSecs -&gt; NSecs
forall a. Integral a =&gt; a -&gt; a -&gt; a
</span><a href="GHC.Real.html#div"><span class="hs-operator hs-var">`div`</span></a></span><span> </span><span class="annot"><span class="annottext">NSecs
</span><span class="hs-number">1000</span></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">IO NSecs
</span><a href="GHC.Conc.POSIX.html#getMonotonicNSec"><span class="hs-identifier hs-var">getMonotonicNSec</span></a></span><span>
</span><span id="line-214"></span><span>
</span><span id="line-215"></span><span class="hs-pragma">{-# NOINLINE</span><span> </span><span class="annot"><a href="GHC.Conc.POSIX.html#prodding"><span class="hs-pragma hs-type">prodding</span></a></span><span> </span><span class="hs-pragma">#-}</span><span>
</span><span id="line-216"></span><span class="annot"><a href="GHC.Conc.POSIX.html#prodding"><span class="hs-identifier hs-type">prodding</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.IORef.html#IORef"><span class="hs-identifier hs-type">IORef</span></a></span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#Bool"><span class="hs-identifier hs-type">Bool</span></a></span><span>
</span><span id="line-217"></span><span id="prodding"><span class="annot"><span class="annottext">prodding :: IORef Bool
</span><a href="GHC.Conc.POSIX.html#prodding"><span class="hs-identifier hs-var hs-var">prodding</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">IO (IORef Bool) -&gt; IORef Bool
forall a. IO a -&gt; a
</span><a href="GHC.IO.Unsafe.html#unsafePerformIO"><span class="hs-identifier hs-var">unsafePerformIO</span></a></span><span> </span><span class="annot"><span class="annottext">(IO (IORef Bool) -&gt; IORef Bool) -&gt; IO (IORef Bool) -&gt; IORef Bool
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-218"></span><span>   </span><span id="local-6989586621679553940"><span class="annot"><span class="annottext">IORef Bool
</span><a href="#local-6989586621679553940"><span class="hs-identifier hs-var">r</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">Bool -&gt; IO (IORef Bool)
forall a. a -&gt; IO (IORef a)
</span><a href="GHC.IORef.html#newIORef"><span class="hs-identifier hs-var">newIORef</span></a></span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="../../ghc-prim/src/GHC.Types.html#False"><span class="hs-identifier hs-var">False</span></a></span><span>
</span><span id="line-219"></span><span>   </span><span class="annot"><span class="annottext">IORef Bool
-&gt; (Ptr (IORef Bool) -&gt; IO (Ptr (IORef Bool))) -&gt; IO (IORef Bool)
forall a. a -&gt; (Ptr a -&gt; IO (Ptr a)) -&gt; IO a
</span><a href="GHC.Conc.Sync.html#sharedCAF"><span class="hs-identifier hs-var">sharedCAF</span></a></span><span> </span><span class="annot"><span class="annottext">IORef Bool
</span><a href="#local-6989586621679553940"><span class="hs-identifier hs-var">r</span></a></span><span> </span><span class="annot"><span class="annottext">Ptr (IORef Bool) -&gt; IO (Ptr (IORef Bool))
forall a. Ptr a -&gt; IO (Ptr a)
</span><a href="GHC.Conc.POSIX.html#getOrSetGHCConcWindowsProddingStore"><span class="hs-identifier hs-var">getOrSetGHCConcWindowsProddingStore</span></a></span><span>
</span><span id="line-220"></span><span>
</span><span id="line-221"></span><span id="local-6989586621679553938"><span class="hs-keyword">foreign</span><span> </span><span class="hs-keyword">import</span><span> </span><span class="annot"><span class="hs-keyword">ccall</span></span><span> </span><span class="annot"><span class="hs-keyword">unsafe</span></span><span> </span><span class="annot"><span class="hs-string">&quot;getOrSetGHCConcWindowsProddingStore&quot;</span></span><span>
</span><span id="line-222"></span><span>    </span><span id="getOrSetGHCConcWindowsProddingStore"><span class="annot"><a href="GHC.Conc.POSIX.html#getOrSetGHCConcWindowsProddingStore"><span class="hs-identifier hs-var">getOrSetGHCConcWindowsProddingStore</span></a></span></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Ptr.html#Ptr"><span class="hs-identifier hs-type">Ptr</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679553938"><span class="hs-identifier hs-type">a</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Ptr.html#Ptr"><span class="hs-identifier hs-type">Ptr</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679553938"><span class="hs-identifier hs-type">a</span></a></span><span class="hs-special">)</span></span><span>
</span><span id="line-223"></span><span>
</span><span id="line-224"></span><span class="annot"><a href="GHC.Conc.POSIX.html#prodServiceThread"><span class="hs-identifier hs-type">prodServiceThread</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span><span>
</span><span id="line-225"></span><span id="prodServiceThread"><span class="annot"><span class="annottext">prodServiceThread :: IO ()
</span><a href="GHC.Conc.POSIX.html#prodServiceThread"><span class="hs-identifier hs-var hs-var">prodServiceThread</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-226"></span><span>  </span><span class="hs-comment">-- NB. use atomicSwapIORef here, otherwise there are race</span><span>
</span><span id="line-227"></span><span>  </span><span class="hs-comment">-- conditions in which prodding is left at True but the server is</span><span>
</span><span id="line-228"></span><span>  </span><span class="hs-comment">-- blocked in select().</span><span>
</span><span id="line-229"></span><span>  </span><span id="local-6989586621679553937"><span class="annot"><span class="annottext">Bool
</span><a href="#local-6989586621679553937"><span class="hs-identifier hs-var">was_set</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">IORef Bool -&gt; Bool -&gt; IO Bool
forall a. IORef a -&gt; a -&gt; IO a
</span><a href="GHC.IORef.html#atomicSwapIORef"><span class="hs-identifier hs-var">atomicSwapIORef</span></a></span><span> </span><span class="annot"><span class="annottext">IORef Bool
</span><a href="GHC.Conc.POSIX.html#prodding"><span class="hs-identifier hs-var">prodding</span></a></span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="../../ghc-prim/src/GHC.Types.html#True"><span class="hs-identifier hs-var">True</span></a></span><span>
</span><span id="line-230"></span><span>  </span><span class="annot"><span class="annottext">Bool -&gt; IO () -&gt; IO ()
forall (f :: * -&gt; *). Applicative f =&gt; Bool -&gt; f () -&gt; f ()
</span><a href="GHC.Base.html#when"><span class="hs-identifier hs-var">when</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Bool -&gt; Bool
</span><a href="../../ghc-prim/src/GHC.Classes.html#not"><span class="hs-identifier hs-var">not</span></a></span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="#local-6989586621679553937"><span class="hs-identifier hs-var">was_set</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">IO ()
</span><a href="GHC.Conc.POSIX.html#wakeupIOManager"><span class="hs-identifier hs-var">wakeupIOManager</span></a></span><span>
</span><span id="line-231"></span><span>
</span><span id="line-232"></span><span class="hs-comment">-- ----------------------------------------------------------------------------</span><span>
</span><span id="line-233"></span><span class="hs-comment">-- Windows IO manager thread</span><span>
</span><span id="line-234"></span><span>
</span><span id="line-235"></span><span class="annot"><a href="GHC.Conc.POSIX.html#ioManager"><span class="hs-identifier hs-type">ioManager</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span><span>
</span><span id="line-236"></span><span id="ioManager"><span class="annot"><span class="annottext">ioManager :: IO ()
</span><a href="GHC.Conc.POSIX.html#ioManager"><span class="hs-identifier hs-var hs-var">ioManager</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-237"></span><span>  </span><span id="local-6989586621679553932"><span class="annot"><span class="annottext">HANDLE
</span><a href="#local-6989586621679553932"><span class="hs-identifier hs-var">wakeup</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">IO HANDLE
</span><a href="GHC.Conc.POSIX.html#c_getIOManagerEvent"><span class="hs-identifier hs-var">c_getIOManagerEvent</span></a></span><span>
</span><span id="line-238"></span><span>  </span><span class="annot"><span class="annottext">HANDLE -&gt; [DelayReq] -&gt; IO ()
</span><a href="GHC.Conc.POSIX.html#service_loop"><span class="hs-identifier hs-var">service_loop</span></a></span><span> </span><span class="annot"><span class="annottext">HANDLE
</span><a href="#local-6989586621679553932"><span class="hs-identifier hs-var">wakeup</span></a></span><span> </span><span class="hs-special">[</span><span class="hs-special">]</span><span>
</span><span id="line-239"></span><span>
</span><span id="line-240"></span><span class="annot"><a href="GHC.Conc.POSIX.html#service_loop"><span class="hs-identifier hs-type">service_loop</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Windows.html#HANDLE"><span class="hs-identifier hs-type">HANDLE</span></a></span><span>          </span><span class="hs-comment">-- read end of pipe</span><span>
</span><span id="line-241"></span><span>             </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">[</span><span class="annot"><a href="GHC.Conc.POSIX.html#DelayReq"><span class="hs-identifier hs-type">DelayReq</span></a></span><span class="hs-special">]</span><span>      </span><span class="hs-comment">-- current delay requests</span><span>
</span><span id="line-242"></span><span>             </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span><span>
</span><span id="line-243"></span><span>
</span><span id="line-244"></span><span id="service_loop"><span class="annot"><span class="annottext">service_loop :: HANDLE -&gt; [DelayReq] -&gt; IO ()
</span><a href="GHC.Conc.POSIX.html#service_loop"><span class="hs-identifier hs-var hs-var">service_loop</span></a></span></span><span> </span><span id="local-6989586621679553929"><span class="annot"><span class="annottext">HANDLE
</span><a href="#local-6989586621679553929"><span class="hs-identifier hs-var">wakeup</span></a></span></span><span> </span><span id="local-6989586621679553928"><span class="annot"><span class="annottext">[DelayReq]
</span><a href="#local-6989586621679553928"><span class="hs-identifier hs-var">old_delays</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-245"></span><span>  </span><span class="hs-comment">-- pick up new delay requests</span><span>
</span><span id="line-246"></span><span>  </span><span id="local-6989586621679553927"><span class="annot"><span class="annottext">[DelayReq]
</span><a href="#local-6989586621679553927"><span class="hs-identifier hs-var">new_delays</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">IORef [DelayReq] -&gt; [DelayReq] -&gt; IO [DelayReq]
forall a. IORef a -&gt; a -&gt; IO a
</span><a href="GHC.IORef.html#atomicSwapIORef"><span class="hs-identifier hs-var">atomicSwapIORef</span></a></span><span> </span><span class="annot"><span class="annottext">IORef [DelayReq]
</span><a href="GHC.Conc.POSIX.html#pendingDelays"><span class="hs-identifier hs-var">pendingDelays</span></a></span><span> </span><span class="hs-special">[</span><span class="hs-special">]</span><span>
</span><span id="line-247"></span><span>  </span><span class="hs-keyword">let</span><span>  </span><span id="local-6989586621679553926"><span class="annot"><span class="annottext">delays :: [DelayReq]
</span><a href="#local-6989586621679553926"><span class="hs-identifier hs-var hs-var">delays</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">(DelayReq -&gt; [DelayReq] -&gt; [DelayReq])
-&gt; [DelayReq] -&gt; [DelayReq] -&gt; [DelayReq]
forall a b. (a -&gt; b -&gt; b) -&gt; b -&gt; [a] -&gt; b
</span><a href="GHC.Base.html#foldr"><span class="hs-identifier hs-var">foldr</span></a></span><span> </span><span class="annot"><span class="annottext">DelayReq -&gt; [DelayReq] -&gt; [DelayReq]
</span><a href="GHC.Conc.POSIX.html#insertDelay"><span class="hs-identifier hs-var">insertDelay</span></a></span><span> </span><span class="annot"><span class="annottext">[DelayReq]
</span><a href="#local-6989586621679553928"><span class="hs-identifier hs-var">old_delays</span></a></span><span> </span><span class="annot"><span class="annottext">[DelayReq]
</span><a href="#local-6989586621679553927"><span class="hs-identifier hs-var">new_delays</span></a></span><span>
</span><span id="line-248"></span><span>
</span><span id="line-249"></span><span>  </span><span id="local-6989586621679553925"><span class="annot"><span class="annottext">NSecs
</span><a href="#local-6989586621679553925"><span class="hs-identifier hs-var">now</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">IO NSecs
</span><a href="GHC.Conc.POSIX.html#getMonotonicUSec"><span class="hs-identifier hs-var">getMonotonicUSec</span></a></span><span>
</span><span id="line-250"></span><span>  </span><span class="hs-special">(</span><span id="local-6989586621679553924"><span class="annot"><span class="annottext">[DelayReq]
</span><a href="#local-6989586621679553924"><span class="hs-identifier hs-var">delays'</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621679553923"><span class="annot"><span class="annottext">DWORD
</span><a href="#local-6989586621679553923"><span class="hs-identifier hs-var">timeout</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">NSecs -&gt; [DelayReq] -&gt; IO ([DelayReq], DWORD)
</span><a href="GHC.Conc.POSIX.html#getDelay"><span class="hs-identifier hs-var">getDelay</span></a></span><span> </span><span class="annot"><span class="annottext">NSecs
</span><a href="#local-6989586621679553925"><span class="hs-identifier hs-var">now</span></a></span><span> </span><span class="annot"><span class="annottext">[DelayReq]
</span><a href="#local-6989586621679553926"><span class="hs-identifier hs-var">delays</span></a></span><span>
</span><span id="line-251"></span><span>
</span><span id="line-252"></span><span>  </span><span id="local-6989586621679553921"><span class="annot"><span class="annottext">DWORD
</span><a href="#local-6989586621679553921"><span class="hs-identifier hs-var">r</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">HANDLE -&gt; DWORD -&gt; IO DWORD
</span><a href="GHC.Conc.POSIX.html#c_WaitForSingleObject"><span class="hs-identifier hs-var">c_WaitForSingleObject</span></a></span><span> </span><span class="annot"><span class="annottext">HANDLE
</span><a href="#local-6989586621679553929"><span class="hs-identifier hs-var">wakeup</span></a></span><span> </span><span class="annot"><span class="annottext">DWORD
</span><a href="#local-6989586621679553923"><span class="hs-identifier hs-var">timeout</span></a></span><span>
</span><span id="line-253"></span><span>  </span><span class="hs-keyword">case</span><span> </span><span class="annot"><span class="annottext">DWORD
</span><a href="#local-6989586621679553921"><span class="hs-identifier hs-var">r</span></a></span><span> </span><span class="hs-keyword">of</span><span>
</span><span id="line-254"></span><span>    </span><span class="annot"><span class="annottext">DWORD
</span><span class="hs-number">0xffffffff</span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-keyword">do</span><span> </span><span class="annot"><span class="annottext">[Char] -&gt; IO ()
forall a. [Char] -&gt; IO a
</span><a href="GHC.Windows.html#throwGetLastError"><span class="hs-identifier hs-var">throwGetLastError</span></a></span><span> </span><span class="annot"><span class="annottext">[Char]
</span><span class="hs-string">&quot;service_loop&quot;</span></span><span>
</span><span id="line-255"></span><span>    </span><span class="annot"><span class="annottext">DWORD
</span><span class="hs-number">0</span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-256"></span><span>        </span><span id="local-6989586621679553918"><span class="annot"><span class="annottext">DWORD
</span><a href="#local-6989586621679553918"><span class="hs-identifier hs-var">r2</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">IO DWORD
</span><a href="GHC.Conc.POSIX.html#c_readIOManagerEvent"><span class="hs-identifier hs-var">c_readIOManagerEvent</span></a></span><span>
</span><span id="line-257"></span><span>        </span><span id="local-6989586621679553916"><span class="annot"><span class="annottext">Bool
</span><a href="#local-6989586621679553916"><span class="hs-identifier hs-var">exit</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span>
</span><span id="line-258"></span><span>              </span><span class="hs-keyword">case</span><span> </span><span class="annot"><span class="annottext">DWORD
</span><a href="#local-6989586621679553918"><span class="hs-identifier hs-var">r2</span></a></span><span> </span><span class="hs-keyword">of</span><span>
</span><span id="line-259"></span><span>                </span><span class="annot"><span class="annottext">DWORD
</span><span class="hs-identifier">_</span></span><span> </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">DWORD
</span><a href="#local-6989586621679553918"><span class="hs-identifier hs-var">r2</span></a></span><span> </span><span class="annot"><span class="annottext">DWORD -&gt; DWORD -&gt; Bool
forall a. Eq a =&gt; a -&gt; a -&gt; Bool
</span><a href="../../ghc-prim/src/GHC.Classes.html#%3D%3D"><span class="hs-operator hs-var">==</span></a></span><span> </span><span class="annot"><span class="annottext">DWORD
</span><a href="GHC.Conc.POSIX.Const.html#io_MANAGER_WAKEUP"><span class="hs-identifier hs-var">io_MANAGER_WAKEUP</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">Bool -&gt; IO Bool
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="../../ghc-prim/src/GHC.Types.html#False"><span class="hs-identifier hs-var">False</span></a></span><span>
</span><span id="line-260"></span><span>                </span><span class="annot"><span class="annottext">DWORD
</span><span class="hs-identifier">_</span></span><span> </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">DWORD
</span><a href="#local-6989586621679553918"><span class="hs-identifier hs-var">r2</span></a></span><span> </span><span class="annot"><span class="annottext">DWORD -&gt; DWORD -&gt; Bool
forall a. Eq a =&gt; a -&gt; a -&gt; Bool
</span><a href="../../ghc-prim/src/GHC.Classes.html#%3D%3D"><span class="hs-operator hs-var">==</span></a></span><span> </span><span class="annot"><span class="annottext">DWORD
</span><a href="GHC.Conc.POSIX.Const.html#io_MANAGER_DIE"><span class="hs-identifier hs-var">io_MANAGER_DIE</span></a></span><span>    </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">Bool -&gt; IO Bool
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="../../ghc-prim/src/GHC.Types.html#True"><span class="hs-identifier hs-var">True</span></a></span><span>
</span><span id="line-261"></span><span>                </span><span class="annot"><span class="annottext">DWORD
</span><span class="hs-number">0</span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">Bool -&gt; IO Bool
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="../../ghc-prim/src/GHC.Types.html#False"><span class="hs-identifier hs-var">False</span></a></span><span> </span><span class="hs-comment">-- spurious wakeup</span><span>
</span><span id="line-262"></span><span>                </span><span class="annot"><span class="annottext">DWORD
</span><span class="hs-identifier">_</span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-keyword">do</span><span> </span><span class="annot"><span class="annottext">DWORD -&gt; IO ()
</span><a href="GHC.Event.Windows.ConsoleEvent.html#start_console_handler"><span class="hs-identifier hs-var">start_console_handler</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">DWORD
</span><a href="#local-6989586621679553918"><span class="hs-identifier hs-var">r2</span></a></span><span> </span><span class="annot"><span class="annottext">DWORD -&gt; Int -&gt; DWORD
forall a. Bits a =&gt; a -&gt; Int -&gt; a
</span><a href="Data.Bits.html#shiftR"><span class="hs-operator hs-var">`shiftR`</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><span class="hs-number">1</span></span><span class="hs-special">)</span><span class="hs-special">;</span><span> </span><span class="annot"><span class="annottext">Bool -&gt; IO Bool
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="../../ghc-prim/src/GHC.Types.html#False"><span class="hs-identifier hs-var">False</span></a></span><span>
</span><span id="line-263"></span><span>        </span><span class="annot"><span class="annottext">Bool -&gt; IO () -&gt; IO ()
forall (f :: * -&gt; *). Applicative f =&gt; Bool -&gt; f () -&gt; f ()
</span><a href="GHC.Base.html#when"><span class="hs-identifier hs-var">when</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Bool -&gt; Bool
</span><a href="../../ghc-prim/src/GHC.Classes.html#not"><span class="hs-identifier hs-var">not</span></a></span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="#local-6989586621679553916"><span class="hs-identifier hs-var">exit</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">(IO () -&gt; IO ()) -&gt; IO () -&gt; IO ()
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="annot"><span class="annottext">HANDLE -&gt; [DelayReq] -&gt; IO ()
</span><a href="GHC.Conc.POSIX.html#service_cont"><span class="hs-identifier hs-var">service_cont</span></a></span><span> </span><span class="annot"><span class="annottext">HANDLE
</span><a href="#local-6989586621679553929"><span class="hs-identifier hs-var">wakeup</span></a></span><span> </span><span class="annot"><span class="annottext">[DelayReq]
</span><a href="#local-6989586621679553924"><span class="hs-identifier hs-var">delays'</span></a></span><span>
</span><span id="line-264"></span><span>
</span><span id="line-265"></span><span>    </span><span id="local-6989586621679553911"><span class="annot"><span class="annottext">DWORD
</span><a href="#local-6989586621679553911"><span class="hs-identifier hs-var">_other</span></a></span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">HANDLE -&gt; [DelayReq] -&gt; IO ()
</span><a href="GHC.Conc.POSIX.html#service_cont"><span class="hs-identifier hs-var">service_cont</span></a></span><span> </span><span class="annot"><span class="annottext">HANDLE
</span><a href="#local-6989586621679553929"><span class="hs-identifier hs-var">wakeup</span></a></span><span> </span><span class="annot"><span class="annottext">[DelayReq]
</span><a href="#local-6989586621679553924"><span class="hs-identifier hs-var">delays'</span></a></span><span> </span><span class="hs-comment">-- probably timeout</span><span>
</span><span id="line-266"></span><span>
</span><span id="line-267"></span><span class="annot"><a href="GHC.Conc.POSIX.html#service_cont"><span class="hs-identifier hs-type">service_cont</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Windows.html#HANDLE"><span class="hs-identifier hs-type">HANDLE</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">[</span><span class="annot"><a href="GHC.Conc.POSIX.html#DelayReq"><span class="hs-identifier hs-type">DelayReq</span></a></span><span class="hs-special">]</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span><span>
</span><span id="line-268"></span><span id="service_cont"><span class="annot"><span class="annottext">service_cont :: HANDLE -&gt; [DelayReq] -&gt; IO ()
</span><a href="GHC.Conc.POSIX.html#service_cont"><span class="hs-identifier hs-var hs-var">service_cont</span></a></span></span><span> </span><span id="local-6989586621679553910"><span class="annot"><span class="annottext">HANDLE
</span><a href="#local-6989586621679553910"><span class="hs-identifier hs-var">wakeup</span></a></span></span><span> </span><span id="local-6989586621679553909"><span class="annot"><span class="annottext">[DelayReq]
</span><a href="#local-6989586621679553909"><span class="hs-identifier hs-var">delays</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-269"></span><span>  </span><span class="annot"><span class="annottext">Bool
</span><span class="hs-identifier">_</span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">IORef Bool -&gt; Bool -&gt; IO Bool
forall a. IORef a -&gt; a -&gt; IO a
</span><a href="GHC.IORef.html#atomicSwapIORef"><span class="hs-identifier hs-var">atomicSwapIORef</span></a></span><span> </span><span class="annot"><span class="annottext">IORef Bool
</span><a href="GHC.Conc.POSIX.html#prodding"><span class="hs-identifier hs-var">prodding</span></a></span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="../../ghc-prim/src/GHC.Types.html#False"><span class="hs-identifier hs-var">False</span></a></span><span>
</span><span id="line-270"></span><span>  </span><span class="annot"><span class="annottext">HANDLE -&gt; [DelayReq] -&gt; IO ()
</span><a href="GHC.Conc.POSIX.html#service_loop"><span class="hs-identifier hs-var">service_loop</span></a></span><span> </span><span class="annot"><span class="annottext">HANDLE
</span><a href="#local-6989586621679553910"><span class="hs-identifier hs-var">wakeup</span></a></span><span> </span><span class="annot"><span class="annottext">[DelayReq]
</span><a href="#local-6989586621679553909"><span class="hs-identifier hs-var">delays</span></a></span><span>
</span><span id="line-271"></span><span>
</span><span id="line-272"></span><span class="annot"><a href="GHC.Conc.POSIX.html#wakeupIOManager"><span class="hs-identifier hs-type">wakeupIOManager</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span><span>
</span><span id="line-273"></span><span id="wakeupIOManager"><span class="annot"><span class="annottext">wakeupIOManager :: IO ()
</span><a href="GHC.Conc.POSIX.html#wakeupIOManager"><span class="hs-identifier hs-var hs-var">wakeupIOManager</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">DWORD -&gt; IO ()
</span><a href="GHC.Conc.POSIX.html#c_sendIOManagerEvent"><span class="hs-identifier hs-var">c_sendIOManagerEvent</span></a></span><span> </span><span class="annot"><span class="annottext">DWORD
</span><a href="GHC.Conc.POSIX.Const.html#io_MANAGER_WAKEUP"><span class="hs-identifier hs-var">io_MANAGER_WAKEUP</span></a></span><span>
</span><span id="line-274"></span><span>
</span><span id="line-275"></span><span class="hs-comment">-- Walk the queue of pending delays, waking up any that have passed</span><span>
</span><span id="line-276"></span><span class="hs-comment">-- and return the smallest delay to wait for.  The queue of pending</span><span>
</span><span id="line-277"></span><span class="hs-comment">-- delays is kept ordered.</span><span>
</span><span id="line-278"></span><span class="annot"><a href="GHC.Conc.POSIX.html#getDelay"><span class="hs-identifier hs-type">getDelay</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Conc.POSIX.html#USecs"><span class="hs-identifier hs-type">USecs</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">[</span><span class="annot"><a href="GHC.Conc.POSIX.html#DelayReq"><span class="hs-identifier hs-type">DelayReq</span></a></span><span class="hs-special">]</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="hs-special">(</span><span class="hs-special">[</span><span class="annot"><a href="GHC.Conc.POSIX.html#DelayReq"><span class="hs-identifier hs-type">DelayReq</span></a></span><span class="hs-special">]</span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Windows.html#DWORD"><span class="hs-identifier hs-type">DWORD</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-279"></span><span id="getDelay"><span class="annot"><span class="annottext">getDelay :: NSecs -&gt; [DelayReq] -&gt; IO ([DelayReq], DWORD)
</span><a href="GHC.Conc.POSIX.html#getDelay"><span class="hs-identifier hs-var hs-var">getDelay</span></a></span></span><span> </span><span class="annot"><span class="annottext">NSecs
</span><span class="hs-identifier">_</span></span><span>   </span><span class="hs-special">[</span><span class="hs-special">]</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">([DelayReq], DWORD) -&gt; IO ([DelayReq], DWORD)
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="hs-special">(</span><span class="hs-special">[</span><span class="hs-special">]</span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">DWORD
</span><a href="GHC.Windows.html#iNFINITE"><span class="hs-identifier hs-var">iNFINITE</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-280"></span><span class="annot"><a href="GHC.Conc.POSIX.html#getDelay"><span class="hs-identifier hs-var">getDelay</span></a></span><span> </span><span id="local-6989586621679553906"><span class="annot"><span class="annottext">NSecs
</span><a href="#local-6989586621679553906"><span class="hs-identifier hs-var">now</span></a></span></span><span> </span><span id="local-6989586621679553905"><span class="annot"><span class="annottext">all :: [DelayReq]
</span><a href="#local-6989586621679553905"><span class="hs-identifier hs-var">all</span></a></span></span><span class="hs-glyph">@</span><span class="hs-special">(</span><span id="local-6989586621679553904"><span class="annot"><span class="annottext">DelayReq
</span><a href="#local-6989586621679553904"><span class="hs-identifier hs-var">d</span></a></span></span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#%3A"><span class="hs-glyph hs-type">:</span></a></span><span> </span><span id="local-6989586621679553903"><span class="annot"><span class="annottext">[DelayReq]
</span><a href="#local-6989586621679553903"><span class="hs-identifier hs-var">rest</span></a></span></span><span class="hs-special">)</span><span>
</span><span id="line-281"></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">case</span><span> </span><span class="annot"><span class="annottext">DelayReq
</span><a href="#local-6989586621679553904"><span class="hs-identifier hs-var">d</span></a></span><span> </span><span class="hs-keyword">of</span><span>
</span><span id="line-282"></span><span>     </span><span class="annot"><a href="GHC.Conc.POSIX.html#Delay"><span class="hs-identifier hs-type">Delay</span></a></span><span> </span><span id="local-6989586621679553902"><span class="annot"><span class="annottext">NSecs
</span><a href="#local-6989586621679553902"><span class="hs-identifier hs-var">time</span></a></span></span><span> </span><span id="local-6989586621679553901"><span class="annot"><span class="annottext">MVar ()
</span><a href="#local-6989586621679553901"><span class="hs-identifier hs-var">m</span></a></span></span><span> </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">NSecs
</span><a href="#local-6989586621679553906"><span class="hs-identifier hs-var">now</span></a></span><span> </span><span class="annot"><span class="annottext">NSecs -&gt; NSecs -&gt; Bool
forall a. Ord a =&gt; a -&gt; a -&gt; Bool
</span><a href="../../ghc-prim/src/GHC.Classes.html#%3E%3D"><span class="hs-operator hs-var">&gt;=</span></a></span><span> </span><span class="annot"><span class="annottext">NSecs
</span><a href="#local-6989586621679553902"><span class="hs-identifier hs-var">time</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-283"></span><span>        </span><span class="annot"><span class="annottext">MVar () -&gt; () -&gt; IO ()
forall a. MVar a -&gt; a -&gt; IO ()
</span><a href="GHC.MVar.html#putMVar"><span class="hs-identifier hs-var">putMVar</span></a></span><span> </span><span class="annot"><span class="annottext">MVar ()
</span><a href="#local-6989586621679553901"><span class="hs-identifier hs-var">m</span></a></span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span><span>
</span><span id="line-284"></span><span>        </span><span class="annot"><span class="annottext">NSecs -&gt; [DelayReq] -&gt; IO ([DelayReq], DWORD)
</span><a href="GHC.Conc.POSIX.html#getDelay"><span class="hs-identifier hs-var">getDelay</span></a></span><span> </span><span class="annot"><span class="annottext">NSecs
</span><a href="#local-6989586621679553906"><span class="hs-identifier hs-var">now</span></a></span><span> </span><span class="annot"><span class="annottext">[DelayReq]
</span><a href="#local-6989586621679553903"><span class="hs-identifier hs-var">rest</span></a></span><span>
</span><span id="line-285"></span><span>     </span><span class="annot"><a href="GHC.Conc.POSIX.html#DelaySTM"><span class="hs-identifier hs-type">DelaySTM</span></a></span><span> </span><span id="local-6989586621679553899"><span class="annot"><span class="annottext">NSecs
</span><a href="#local-6989586621679553899"><span class="hs-identifier hs-var">time</span></a></span></span><span> </span><span id="local-6989586621679553898"><span class="annot"><span class="annottext">TVar Bool
</span><a href="#local-6989586621679553898"><span class="hs-identifier hs-var">t</span></a></span></span><span> </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">NSecs
</span><a href="#local-6989586621679553906"><span class="hs-identifier hs-var">now</span></a></span><span> </span><span class="annot"><span class="annottext">NSecs -&gt; NSecs -&gt; Bool
forall a. Ord a =&gt; a -&gt; a -&gt; Bool
</span><a href="../../ghc-prim/src/GHC.Classes.html#%3E%3D"><span class="hs-operator hs-var">&gt;=</span></a></span><span> </span><span class="annot"><span class="annottext">NSecs
</span><a href="#local-6989586621679553899"><span class="hs-identifier hs-var">time</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-286"></span><span>        </span><span class="annot"><span class="annottext">STM () -&gt; IO ()
forall a. STM a -&gt; IO a
</span><a href="GHC.Conc.Sync.html#atomically"><span class="hs-identifier hs-var">atomically</span></a></span><span> </span><span class="annot"><span class="annottext">(STM () -&gt; IO ()) -&gt; STM () -&gt; IO ()
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="annot"><span class="annottext">TVar Bool -&gt; Bool -&gt; STM ()
forall a. TVar a -&gt; a -&gt; STM ()
</span><a href="GHC.Conc.Sync.html#writeTVar"><span class="hs-identifier hs-var">writeTVar</span></a></span><span> </span><span class="annot"><span class="annottext">TVar Bool
</span><a href="#local-6989586621679553898"><span class="hs-identifier hs-var">t</span></a></span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="../../ghc-prim/src/GHC.Types.html#True"><span class="hs-identifier hs-var">True</span></a></span><span>
</span><span id="line-287"></span><span>        </span><span class="annot"><span class="annottext">NSecs -&gt; [DelayReq] -&gt; IO ([DelayReq], DWORD)
</span><a href="GHC.Conc.POSIX.html#getDelay"><span class="hs-identifier hs-var">getDelay</span></a></span><span> </span><span class="annot"><span class="annottext">NSecs
</span><a href="#local-6989586621679553906"><span class="hs-identifier hs-var">now</span></a></span><span> </span><span class="annot"><span class="annottext">[DelayReq]
</span><a href="#local-6989586621679553903"><span class="hs-identifier hs-var">rest</span></a></span><span>
</span><span id="line-288"></span><span>     </span><span id="local-6989586621679553896"><span class="annot"><span class="annottext">DelayReq
</span><a href="#local-6989586621679553896"><span class="hs-identifier hs-var">_otherwise</span></a></span></span><span> </span><span class="hs-glyph">-&gt;</span><span>
</span><span id="line-289"></span><span>        </span><span class="hs-comment">-- delay is in millisecs for WaitForSingleObject</span><span>
</span><span id="line-290"></span><span>        </span><span class="hs-keyword">let</span><span> </span><span id="local-6989586621679553894"><span class="annot"><span class="annottext">micro_seconds :: NSecs
</span><a href="#local-6989586621679553894"><span class="hs-identifier hs-var hs-var">micro_seconds</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">DelayReq -&gt; NSecs
</span><a href="GHC.Conc.POSIX.html#delayTime"><span class="hs-identifier hs-var">delayTime</span></a></span><span> </span><span class="annot"><span class="annottext">DelayReq
</span><a href="#local-6989586621679553904"><span class="hs-identifier hs-var">d</span></a></span><span> </span><span class="annot"><span class="annottext">NSecs -&gt; NSecs -&gt; NSecs
forall a. Num a =&gt; a -&gt; a -&gt; a
</span><a href="GHC.Num.html#-"><span class="hs-glyph hs-var">-</span></a></span><span> </span><span class="annot"><span class="annottext">NSecs
</span><a href="#local-6989586621679553906"><span class="hs-identifier hs-var">now</span></a></span><span>
</span><span id="line-291"></span><span>            </span><span id="local-6989586621679553889"><span class="annot"><span class="annottext">milli_seconds :: NSecs
</span><a href="#local-6989586621679553889"><span class="hs-identifier hs-var hs-var">milli_seconds</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">NSecs
</span><a href="#local-6989586621679553894"><span class="hs-identifier hs-var">micro_seconds</span></a></span><span> </span><span class="annot"><span class="annottext">NSecs -&gt; NSecs -&gt; NSecs
forall a. Num a =&gt; a -&gt; a -&gt; a
</span><a href="GHC.Num.html#%2B"><span class="hs-operator hs-var">+</span></a></span><span> </span><span class="annot"><span class="annottext">NSecs
</span><span class="hs-number">999</span></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">NSecs -&gt; NSecs -&gt; NSecs
forall a. Integral a =&gt; a -&gt; a -&gt; a
</span><a href="GHC.Real.html#div"><span class="hs-operator hs-var">`div`</span></a></span><span> </span><span class="annot"><span class="annottext">NSecs
</span><span class="hs-number">1000</span></span><span>
</span><span id="line-292"></span><span>        </span><span class="hs-keyword">in</span><span> </span><span class="annot"><span class="annottext">([DelayReq], DWORD) -&gt; IO ([DelayReq], DWORD)
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">[DelayReq]
</span><a href="#local-6989586621679553905"><span class="hs-identifier hs-var">all</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">NSecs -&gt; DWORD
forall a b. (Integral a, Num b) =&gt; a -&gt; b
</span><a href="GHC.Real.html#fromIntegral"><span class="hs-identifier hs-var">fromIntegral</span></a></span><span> </span><span class="annot"><span class="annottext">NSecs
</span><a href="#local-6989586621679553889"><span class="hs-identifier hs-var">milli_seconds</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-293"></span><span>
</span><span id="line-294"></span><span class="hs-keyword">foreign</span><span> </span><span class="hs-keyword">import</span><span> </span><span class="annot"><span class="hs-keyword">ccall</span></span><span> </span><span class="annot"><span class="hs-keyword">unsafe</span></span><span> </span><span class="annot"><span class="hs-string">&quot;getIOManagerEvent&quot;</span></span><span> </span><span class="hs-comment">-- in the RTS (ThrIOManager.c)</span><span>
</span><span id="line-295"></span><span>  </span><span id="c_getIOManagerEvent"><span class="annot"><a href="GHC.Conc.POSIX.html#c_getIOManagerEvent"><span class="hs-identifier hs-var">c_getIOManagerEvent</span></a></span></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="annot"><a href="GHC.Windows.html#HANDLE"><span class="hs-identifier hs-type">HANDLE</span></a></span><span>
</span><span id="line-296"></span><span>
</span><span id="line-297"></span><span class="hs-keyword">foreign</span><span> </span><span class="hs-keyword">import</span><span> </span><span class="annot"><span class="hs-keyword">ccall</span></span><span> </span><span class="annot"><span class="hs-keyword">unsafe</span></span><span> </span><span class="annot"><span class="hs-string">&quot;readIOManagerEvent&quot;</span></span><span> </span><span class="hs-comment">-- in the RTS (ThrIOManager.c)</span><span>
</span><span id="line-298"></span><span>  </span><span id="c_readIOManagerEvent"><span class="annot"><a href="GHC.Conc.POSIX.html#c_readIOManagerEvent"><span class="hs-identifier hs-var">c_readIOManagerEvent</span></a></span></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="annot"><a href="GHC.Word.html#Word32"><span class="hs-identifier hs-type">Word32</span></a></span><span>
</span><span id="line-299"></span><span>
</span><span id="line-300"></span><span class="hs-keyword">foreign</span><span> </span><span class="hs-keyword">import</span><span> </span><span class="annot"><span class="hs-keyword">ccall</span></span><span> </span><span class="annot"><span class="hs-keyword">unsafe</span></span><span> </span><span class="annot"><span class="hs-string">&quot;sendIOManagerEvent&quot;</span></span><span> </span><span class="hs-comment">-- in the RTS (ThrIOManager.c)</span><span>
</span><span id="line-301"></span><span>  </span><span id="c_sendIOManagerEvent"><span class="annot"><a href="GHC.Conc.POSIX.html#c_sendIOManagerEvent"><span class="hs-identifier hs-var">c_sendIOManagerEvent</span></a></span></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Word.html#Word32"><span class="hs-identifier hs-type">Word32</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span><span>
</span><span id="line-302"></span><span>
</span><span id="line-303"></span><span class="hs-keyword">foreign</span><span> </span><span class="hs-keyword">import</span><span> </span><span class="hs-identifier">WINDOWS_CCONV</span><span> </span><span class="hs-string">&quot;WaitForSingleObject&quot;</span><span>
</span><span id="line-304"></span><span>   </span><span id="c_WaitForSingleObject"><span class="annot"><a href="GHC.Conc.POSIX.html#c_WaitForSingleObject"><span class="hs-identifier hs-var">c_WaitForSingleObject</span></a></span></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Windows.html#HANDLE"><span class="hs-identifier hs-type">HANDLE</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Windows.html#DWORD"><span class="hs-identifier hs-type">DWORD</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="annot"><a href="GHC.Windows.html#DWORD"><span class="hs-identifier hs-type">DWORD</span></a></span><span>
</span><span id="line-305"></span><span>
</span><span id="line-306"></span></pre></body></html>